Search code examples
dockerdocker-rundocker-entrypoint

Add arguments to entrypoint/cmd for different containers


I have this simple node.js image:

FROM node:12

USER root

WORKDIR /app

COPY package.json .
COPY package-lock.json .

RUN npm i --production

COPY . .

ENTRYPOINT node dist/main.js

ultimately, I just want to be able to pass different arguments to node dist/main.js like so:

docker run -d my-image --foo --bar=3

so that the executable when run is

node dist/main.js --foo --bar=3

I have read about CMD / ENTRYPOINT and I don't know how to do this, anybody know?


Solution

  • This seems to work:

    ENTRYPOINT ["node", "dist/main.js"]
    CMD []
    

    which appears to be equivalent to just:

    ENTRYPOINT ["node", "dist/main.js"]
    

    you can't seem to use single quotes - double quotes are necessary, and you have to use shell syntax..not sure why, but this style does not work:

    ENTRYPOINT node dist/main.js