简体   繁体   中英

How can I run container with process.argv in Docker?

My app requires that user input 3 parameters after node index.js, for example:
node index.js 1 1 1 .
When I used just Dockerfile, I wrote this there:
ENTRYPOINT ["node", "index.js"]
And after I executed in terminal command:
docker run 1 1 1 . It's worked, arguments was in process.argv
But now I need to use docker-compose.yml, and I don't know what I must do.

As the values are "static" for a running container and will not change during runtime of the container you could simply use environment variables.

Inside your docker-compose.yml define environment variables (used as default values) for the container like:

<service_name>:
  environment:
    - value1: 1
    - value2: 1
    - value3: 1

Refer to: https://docs.docker.com/compose/environment-variables/

Change the entrypoint to use the environment variables like:

ENTRYPOINT ["node", "index.js", "$value1", "$value2", "$value3"]

When you start the container you can simply change the values with:

docker-compose run -e value1=2 

Hope this is what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM