How to override the CMD command in the docker run line

How you can replace the cdm based on the docker documentation:

You can override the CMD command

  • mount points added to the host don't show up in a running docker container
  • docker cp a folder with a relative symlink: invalid symlink
  • How to check the docker is installed by apt-get in ubuntu?
  • Why does trying to kill a process in Docker container take me out of it?
  • Docker - unable to link container
  • Installing openssh-server, g++, gdb, and gdbserver in a docker container | Visual C++ for Linux Development + Docker
  • 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/"]

    the docker run command is:

    docker run --name test test/test-backend

    I tried

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

    But the console say this error:

    System error: exec: "cmd": executable file not found in $PATH

  • Detach from docker run from script without killing container
  • Docker inspect format to retreive IP of a particular network
  • Is it possible to execute CMD at the middle of docker file?
  • log_driver param doesn't work on ansible 2.0
  • Getting docker daemon not running error
  • Docker History Base Image Add:sha256hash
  • 3 Solutions collect form web for “How to override the CMD command in the docker run line”

    The right way to do it is deleting cmd [“…”]

     docker run --name test test/test-backend /srv/www/bin/

    The Dockerfile uses CMD instruction which allows defaults for the container being executed.

    The below line will execute the script /srv/www/bin/ as its already provide in CMD instruction in your Dockerfile as a default value, which internally gets executed as /bin/sh -c /srv/www/bin/ during runtime.

     docker run --name test test/test-backend 

    Now say if you want to run some thing else, just add that at a end of the docker run. Now below line should run bash instead.

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

    Ref: Dockerfile Best Practices

    For those using docker-compose:

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

    In my case I’m reusing the same docker service to run the development and production builds of my react application:

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

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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.