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

ENTRYPOINT ["/usr/sbin/apache2ctl"]

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") ?


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.

  • Wouldn't that execute "/usr/sbin/apache2ctl /bin/bash"? (because your example doesn't override the entrypoint it will use the entrypoint defined in the Dockerfile -- or am I missing something?)
    – warp
    May 12 '14 at 17:56
  • Is that something which is different for older/newer docker versions perhaps? It certainly runs the entrypoint for me: gist.github.com/warpr/26a5cc471dce7fcf9021 . This is using docker 0.10.0 on Ubuntu 13.10.
    – warp
    May 12 '14 at 21:56
  • 4
    I know passing --entrypoint overrides the entrypoint. But when I use --entrypoint, how do I override CMD to be empty? (For bash I can use something like -i or --login, but not all entrypoints I might want to use will have an equivalent "dummy" argument).
    – warp
    May 13 '14 at 13:24
  • 1
    At least in Docker v1.11.1 it appears that overriding the --entrypoint also prevents the normal appending of the CMD to the entrypoint. That only seems to happen when the entrypoint is not overridden. Aug 23 '17 at 20:59
  • 6
    Why there is a -i after $IMAGE?
    – Eyal Levin
    Oct 21 '18 at 12:57

See: https://docs.docker.com/engine/reference/run/#overriding-dockerfile-image-defaults

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%.

  • Oops, I overlooked a detail. Except for shortening --login to -l I guess your solution is already as good as it gets.
    – Simon Thum
    Jun 12 '14 at 8:02
  • Here's a fun thing I saw today: the command isn't overridden, it's appended. Here's the PS from inside the container. Note that the command I added was echo "setting up the db" and the built in command is /usr/bin/geth. Also I set entrypoint to be "". 1 ? Ssl 0:00 /usr/bin/geth echo setting up db
    – Paul S
    Feb 20 '16 at 9:08
  • The docker reference link no longer works - can't find an obvious replacement for it. Apr 26 '17 at 11:56
  • I just fixed it, but I also found it hard to find ;(
    – Simon Thum
    Apr 27 '17 at 8:45

For anyone comming here to override entrypoint AND command to pass other command, e.g. run bash instead of entrypoint script and then run some other command with parameters (was not clear to me from other answers):

 docker run [other options] --entrypoint '/bin/sh' $IMAGE -c 'npm link gulp gulp-sass gulp-sourcemaps'

-c 'npm link ...' is parameter for /bin/sh so here you may pass any command you would want to run in container. /bin/sh is for alpine images, /bin/bash most likely for other images.

  • 2
    just an addtion shell commands should be json based writen , so instead of quoting with single quotes '...' use double quotes "..." Sep 11 '17 at 16:44
  • 2
    Or just pass as many --entrypoint arguments as you want
    – Nick Roz
    Jul 17 '19 at 16:11
  • this does not seem to work: "exec: \"-c\": executable file not found in $PATH": unknown.
    – Richard
    Sep 19 '19 at 17:13
  • Check the path in container, maybe it really does not exist. Most of the images have /bin/sh but yours might not be that case. Sep 20 '19 at 12:07
  • I think this the best and most complete answer, though as @JimmyObonyoAbor points out, it should be corrected to use double-quotes (").
    – NYCeyes
    Apr 13 '20 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.