Answer the question
In order to leave comments, you need to log in
Why does the script run as a node application when starting the sh docker container?
Hello everyone)
There is the following Dockerfile:
FROM node:16-alpine
ENV PORT=5014
ENV NODE_ENV=development
ENV DATABASE_PORT=3306
WORKDIR /usr/src/app
RUN apk update && apk add bash tini tzdata
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime \
&& echo "Europe/Moscow" > /etc/timezone
RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
RUN chmod a+x wait-for-it.sh
COPY package*.json ./
COPY ["src", "./src"]
COPY ["test", "./test"]
RUN npm ci
RUN chmod a+x src/start.sh
EXPOSE 8080
CMD ["src/start.sh"]
#!/bin/bash
set -e
./wait-for-it.sh "food_calc_mysql:${DATABASE_PORT}" --timeout=1 -- echo "Database is up"
if ; then
exec npx nodemon --exec "node ./src/bin/www"
else
echo "NODE_ENV is not set"
exit 1
fi
/usr/src/app/src/start.sh:5
./wait-for-it.sh "food_calc_mysql:${DATABASE_PORT}" --timeout=1 -- echo "Database is up"
^
SyntaxError: Unexpected token '/'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Answer the question
In order to leave comments, you need to log in
In the base image, the ENTRYPOINT is set to this script .
In particular, it says that if the command does not look like an executable, then it is assumed that this is JS that needs to be executed by the node.
In your case, probably the easiest is to set the full path to the file in CMD
CMD ["/usr/src/app/src/start.sh"]
Most likely the base image you're using has an ENTRYPOINT set up that turns your src/start.sh into node src/start.sh or something.
See what exactly is written in ENTRYPOIN and adjust or replace it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question