Getting started with Docker might seem complex at first, but it all begins with simple concepts. One of the most important is understanding what Docker images are and how to use them to create containers. In this article, we walk through the process of pulling your first image from Docker Hub and launching a container from it, using a very popular example.
First Docker Image
Docker Hub is a public repository that contains a wide range of Docker images, from simple tools to complex applications. You can begin by downloading a basic image to understand how Docker works. For learning purposes, pull the hello-world
image, which is designed to demonstrate Docker's core functionality. To start, execute the docker pull
command in your terminal (CMD or PowerShell), passing the image name as an argument:
docker pull hello-world
Understanding Output Messages
Running the command starts downloading the image from Docker Hub. You'll see the following messages:
- Using default tag: latest — Docker uses tags to manage image versions. If no tag is specified, Docker pulls the
latest
tag by default, which typically refers to the most recent stable version. - Pulling from library/hello-world — Indicates the image is being pulled from Docker's official
library
collection on Docker Hub. - c1ec31eb5944: Pull complete — Each Docker image is built from layers. This message shows that one of those layers has been successfully downloaded.
- Digest: sha256:ac69084025c66051... — A SHA256 digest uniquely identifies the image. It's used to verify the image’s integrity during transfer.
- Status: Downloaded newer image — Confirms the image has been successfully downloaded.
- docker.io — This is the default domain used by Docker to fetch images from Docker Hub. The full image path is
library/hello-world:latest
.
First Docker Container
With the image pulled, you can now create a running container from it. Use the following command:
docker run hello-world
Running this command launches a container from the hello-world
image. Here's what happens:
- The Docker client connects to the Docker daemon (dockerd), the core server-side component that handles container creation, execution, and management.
- The Docker daemon pulls the
hello-world
image (if it’s not already present) and creates a container that runs a test program. - The program generates an output message, which the daemon sends back to the Docker client and displays in your terminal.
Container Status
Notably, the hello-world
container shuts down automatically after displaying the output. Its status is shown as Exited.
Keep in mind, containers behave differently depending on the image. For example, a container based on an HTTP server image will continue running until manually stopped by the user—in that case, the container’s will stay active.