CodeBlanks Logo Icon CodeBlanks

The hello-world container

Learn to test the install by running the first container.

What does hello-world prove?

The output of the hello-world container tells you four steps completed successfully in the background:

  1. The CLI connected to the daemon.
  2. The daemon pulled the image from Docker Hub.
  3. The daemon created a new container from the image and ran the program.
  4. The daemon streamed the output to the CLI, which sent it to the terminal.
docker run hello-world

Stopped containers pile up

hello-world stops when it finishes but isn't removed. docker ps -a also shows stopped containers; every run adds a new one. You need to use --rm or clean up with docker container prune:

$ docker ps -a
CONTAINER ID   IMAGE         STATUS                     NAMES
a1b2c3d4e5f6   hello-world   Exited (0) 5 seconds ago   jolly_tesla
$ docker container prune -f

Practice Try and clean up

Write three commands: run hello-world; list all containers (including stopped ones); clean up the stopped containers without asking for confirmation.

Starter code

terminal
# buraya yaz

Sample solution

terminal
docker run hello-world
docker ps -a
docker container prune -f

Expected output

Hello from Docker!
CONTAINER ID   IMAGE         STATUS                     NAMES
a1b2c3d4e5f6   hello-world   Exited (0) 2 seconds ago   jolly_tesla
Deleted Containers:
a1b2c3d4e5f6

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is different when hello-world is run a second time?

  • The same container is reused
  • The output becomes Turkish
  • The download step is skipped because the image is local Correct answer
  • It gives an error

Explanation: Each docker run creates a new container; the image comes from the cache.

2 List stopped containers too.

Question
docker ps ____
Answer
docker ps -a

Explanation: -a (all) shows all containers.

3 Match.

Term Meaning
Exited (0) Finished successfully
docker ps -a All containers
container prune Removes stopped ones
jolly_tesla Automatically given name

All lessons in Beginner