Dockerfile
# Use an official Node.js runtime as a parent image
FROM node:18
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Install app dependencies
RUN npm install
# Bundle app source
COPY lib/ ./lib
COPY sql/ ./sql
COPY tsconfig.json ./
RUN npm run build
# Specify the command to run your app with custom arguments
ENTRYPOINT npm run start
Usual command I use in nodejs to start my app (when not using docker) :
npm run start -- --host "127.0.0.1" --port 3306 --user "root"
After running docker build -t demo:latest .
I have tried every possible combination of arguments without success.
docker run demo -- -- host "127.0.0.1" --port 3306 --user "root"
<= does not forward correctly the arguments
How to correctly forward them?
2
Answers
Change
ENTRYPOINT npm run start
toENTRYPOINT ["npm", "run", "start"]
Change
ENTRYPOINT npm run start
toENTRYPOINT ["npm", "run", "start"]
Explanation
The documentation for
ENTRYPOINT
says that there are two forms of the directive:The exec form, which is the preferred form:
Which does pass command line args from
docker run
.The shell form:
Which does not pass command line args from
docker run
.Relevant bits, quoted directly from the documentation:
Exec form
Shell form