➜ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
...
If you look at the output you will see that docker does few things for us.
It will check if the image is available locally.
If not, it will be pulled down from the remote repository.
It initializes the image's name and resources containers needs like CPU, IP, Memory etc.
After that it will run the container.
When container is started, it will execute a command.
Command is defined in image itself. We will talk about this later.
If you want to see container that are stopped you can use --all option.
docker container list --all OR docker ps --all
➜ docker container list --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb11cd638c55 hello-world "/hello" 9 minutes ago Exited (0) 9 minutes ago stoic_shtern
This will run a busybox and at the end it will execute the command sleep 5000.
This kind of emulates a long running process, as container will not stop unless command exits.
If you list the container right now (in new terminal of course), you will see status is different.
It is not Exited.
➜ docker container list
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d7acdce83ad6 busybox "sleep 5000" 23 seconds ago Up 21 seconds gallant_hodgkin