How to override CMD command in docker launch line

How can you replace cdm based on docker documentation: https://docs.docker.com/reference/builder/#cmd

You can override the CMD command

Dockerfile:

RUN chmod +x /srv/www/bin/* & chmod -R 755 /srv/www/app RUN pip3 install -r /srv/www/app/pip-requirements.txt EXPOSE 80 CMD ["/srv/www/bin/gunicorn.sh"] 

docker launch command:

 docker run --name test test/test-backend 

I tried

 docker run --name test test --cmd ["/srv/www/bin/gunicorn.sh"] docker run --name test test cmd ["/srv/www/bin/gunicorn.sh"] 

But the console will say this error:

 System error: exec: "cmd": executable file not found in $PATH 
+5
source share
3 answers

The correct way to do this is to remove cmd ["..."]

  docker run --name test test/test-backend /srv/www/bin/gunicorn.sh 
+6
source

Dockerfile uses the CMD command, which allows you to set default values ​​for the container that is running.

The line below will execute script /srv/www/bin/gunicorn.sh , since it already provides the Dockerfile value in the CMD instruction in your Dockerfile , which is executed inside /bin/sh -c /srv/www/bin/gunicorn.sh at run time /bin/sh -c /srv/www/bin/gunicorn.sh .

  docker run --name test test/test-backend 

Now tell me if you want to run something else, just add this to the end of docker run . Now below the line you should run bash .

 docker run --name test test/test-backend /bin/bash 

Link: Best Dockerfile Recommendations

+1
source

For those using docker-compose:

docker-compose run [your-service-name-here-from-docker-compose.yml] /srv/www/bin/gunicorn.sh

In my case, I reuse the same docker service to start development and create my reaction applications:

docker-compose run my-react-app npm run build

webpack.config.production.js my webpack.config.production.js and webpack.config.production.js dist app. But yes, to the original question, you can override CMD in the CLI.

0
source

Source: https://habr.com/ru/post/1233093/


All Articles