From charlesreid1

To run your first Docker container, Docker provides a hello-world container.

Get the container image

You can either explicitly pull the hello-world container from Dockerhub (recommended), or you can let Docker take care of it for you.

Pull container image from dockerhub

Pull the hello-world image from Dockerhub:

$ docker pull hello-world

List all container images

Use the docker images command to list all the container images in Docker:

$ docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
hello-world                     latest              05a3bd381fc2        10 days ago         1.84kB

Run the hello-world container

To run the container, use the docker run command:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
5b0f327be733: Pull complete
Digest: sha256:1f19634d26995c320618d94e6f29c09c6589d5df3c063287a00e6de8458f8242
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/


Remove the container image

Now remove the image from your system entirely. This is a two step process:

  • Remove the stopped process
  • Remove the container image

Remove the stopped process

After you run the hello-world container, it will print out its hello world message, then shut down. However, if you try to remove the image straight away, you'll get an error:

$ docker rmi 05a3bd381fc2
Error response from daemon: conflict: unable to delete 05a3bd381fc2 (must be forced) - image is being used by stopped container 31155e25a61e

This is because, even when a container image has finished running, it remains in the process queue as a "stopped" process. You have to delete the stopped process first, then you can delete the image.


To list all processes, including stopped processes:

$ docker ps -a

Use the container ID or the name to remove the stopped image:

$ docker rm 31155e25a61e

$ docker rm quirky_twain

Remove the container image

Now that you've removed the stopped process, you can remove the container image using its name or its ID:

$ docker rmi 05a3bd381fc2
Untagged: hello-world:latest
Untagged: hello-world@sha256:1f19634d26995c320618d94e6f29c09c6589d5df3c063287a00e6de8458f8242
Deleted: sha256:05a3bd381fc2470695a35f230afefd7bf978b566253199c4ae5cc96fafa29b37
Deleted: sha256:3a36971a9f14df69f90891bf24dc2b9ed9c2d20959b624eab41bbf126272a023

or

$ docker rm hello-world


Flags