Categories
JavaScript Answers

How to use docker run command to pass arguments to CMD in Dockerfile?

Spread the love

To use docker run command to pass arguments to CMD in Dockerfile, we run CMD with an array.

For instance, we write

CMD ["sh", "-c", "node server.js ${cluster} ${environment}"]

in our Dockerfile to run the sh command with the arguments after it.

cluster and environment are the environment variables we defined in the docket-compose.yml file like

node:
  environment:
    - environment=dev
    - cluster=0

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *