The hello-world container
- Docker & Kubernetes course
- Beginner
- Lesson 10/82
- 4 min
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:
- The CLI connected to the daemon.
- The daemon pulled the image from Docker Hub.
- The daemon created a new container from the image and ran the program.
- The daemon streamed the output to the CLI, which sent it to the terminal.
docker run hello-worldStopped 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 -fPractice 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
# buraya yazSample solution
docker run hello-world
docker ps -a
docker container prune -fExpected 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.
docker ps ____
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 |