Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some docker images require a command when run?

Tags:

docker

I find when using docker run I sometimes don't need to add a "command", while sometimes a "command" is a must. E.g. when running the ubuntu image a command isn't required:

# docker run ubuntu
#

While when running mstormo/suse:

# docker run mstormo/suse
Error response from daemon: No command specified
# docker run mstormo/suse bash
#

So is this related to the specified image?

like image 797
Nan Xiao Avatar asked Mar 17 '16 03:03

Nan Xiao


People also ask

Why do we use Docker Run command?

The docker run command creates a container from a given image and starts the container using a given command. It is one of the first commands you should become familiar with when starting to work with Docker.

What does run command do in Dockerfile?

The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command. That is, docker run is equivalent to the API /containers/create then /containers/(id)/start .

Which Docker command is mandatory before pushing the image?

The docker push command takes the name of the image. It will know where to push our Docker image by looking at the image name because the name contains the registry location.

What is the command you run to run a container from an image?

To run an image inside of a container, we use the docker run command. The docker run command requires one parameter and that is the image name.


1 Answers

The Docker image can optionally include a default command to run when none is given on the command-line.

If no default command is given, then it has to be provided by the caller.

If you look at the Dockerfile for ubuntu, they have

CMD ["/bin/bash"]

So if you don't say otherwise, it will run bash for you.

No such setting in mstormo/suse.

like image 105
Thilo Avatar answered Oct 22 '22 02:10

Thilo