skip to Main Content

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


  1. Chosen as BEST ANSWER

    Change ENTRYPOINT npm run start to ENTRYPOINT ["npm", "run", "start"]


  2. Change ENTRYPOINT npm run start to ENTRYPOINT ["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:

    ENTRYPOINT ["executable", "param1", "param2"]
    

    Which does pass command line args from docker run.

    The shell form:

    ENTRYPOINT command param1 param2
    

    Which does not pass command line args from docker run.


    Relevant bits, quoted directly from the documentation:

    Exec form

    Command line arguments to docker run <image> will be appended after all elements in an exec form ENTRYPOINT, and will override all elements specified using CMD. This allows arguments to be passed to the entry point, i.e., docker run <image> -d will pass the -d argument to the entry point.

    Shell form

    This form will use shell processing to substitute shell environment variables, and will ignore any CMD or docker run command line arguments.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search