The key difference between docker run versus docker-compose is that docker run is entirely command line based, while docker-compose reads configuration data from a YAML file. The second major difference is that docker run can only start one container at a time, while docker-compose will configure and run multiple.
docker container run is a shorthand for docker container create and docker container start . So, by definition, it creates a new container every time.
The docker run command creates running containers from images and can run commands inside them. When using the docker run command, a container can run a default action (if it has one), a user specified action, or a shell to be used interactively.
Docker Run vs Docker Exec! This is a fairly common question – but has a simple answer! In short, docker run is the command you use to create a new container from an image, whilst docker exec lets you run commands on an already running container! Easy!
docker run
= docker create
+ docker start
.
From docker documentation
The docker create command creates a writeable container layer over the specified image and prepares it for running the specified command. The container ID is then printed to STDOUT. This is similar to docker run -d except the container is never started. You can then use the docker start command to start the container at any point.
This is useful when you want to set up a container configuration ahead of time so that it is ready to start when you need it. The initial status of the new container is created.
docker create
command creates a writeable container from the image and prepares it for running.
docker run
command creates the container (same as docker create
) and starts it.
The other answers have this covered but I thought I'd show the equivalent shell command-lines because it makes it really clear:
$ docker run myimage
is the same as
$ docker start -a $(docker create myimage)
Here, docker create
is used to create a container from the named image and outputs the created container id and docker start
is used to start the container with that id. The -a
option causes the terminal to attach so that the container runs in the foreground which is the default behaviour of docker run
.
A container that has been created but never started will have a Created
status; this can be seen with docker container ls -a
.
I'm new to docker and just got around to playing with it;
My take is that docker run essentially does the following: (in the order of..) docker create, docker start, docker attach , since it immediately attaches to the active shell after you do the 'run' command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With