# How can I override CMD when running a docker image?

## The Question :

161 people think this question is useful

I want to inspect a docker image created by someone else with both an entrypoint and cmd specified, for example:

ENTRYPOINT ["/usr/sbin/apache2ctl"]
CMD ["-D", "FOREGROUND"]

I currently do:

docker run --interactive --tty --entrypoint=/bin/bash $IMAGE --login Is there a way to override CMD to be empty (so I don’t have to use “–login”) ? The Question Comments : ## The Answer 1 175 people think this answer is useful You could just enter via docker run -it --entrypoint=/bin/bash$IMAGE -i (you ‘ll launch a new container from the image and get a bash shell in interactive mode), then run the entrypoint command in that container.

You can then inspect the running container in the state it should be running.

EDIT: Since Docker 1.3 you can use exec to run a process in a running container. Start your container as you ‘d normally do, and then enter it by issuing:

docker exec -it $CONTAINER_ID /bin/bash Assuming bash is installed you will be given shell access to the running container. ## The Answer 2 34 people think this answer is useful Relevant portion: CMD (Default Command or Options) Recall the optional COMMAND in the Docker commandline:$ docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]

This command is optional because the person who created the IMAGE may have already provided a default COMMAND using the Dockerfile CMD. As the operator (the person running a container from the image), you can override that CMD just by specifying a new COMMAND.

If the image also specifies an ENTRYPOINT then the CMD or COMMAND get appended as arguments to the ENTRYPOINT.

So to do what you want you need only specify a cmd, and override using /bin/bash. Not quite “empty”, but it get the job done 99%.