To run a docker image, first it needs to be pulled on the system or host machine where it would be run as a container.
In this article, we will understand how to do this with examples

Docker pull

To download or pull an image from a docker registry, docker pull command is used.
Its syntax is

docker pull <image-name>:<tag>

Here,
<image-name> is the name of image
<tag> is the tag of image.

If you don’t specify a tag, docker by default pulls the latest image. So,

docker pull <image-name>

is the same as

docker pull <image-name>:latest

Below is an example of pulling java image from docker registry

docker pull openjdk:17-jdk-slim

where openjdk is the image name and 17-jdk-slim is its tag.

Docker registry

A Docker registry is a centralized service and repository for storing and distributing Docker images.
It allows developers to easily upload and manage their images, and provides a convenient way for users to download and use those images in projects.

Whenever you run docker pull command, it will search the image name and tag in configured registry and download the image to the local system.

There are two types of docker registries
1. Public
These registries are accessible to anyone so that users can push images, pull and use the images in applications.
DockerHub is the most common example of this.
2. Private
As the name suggests, private registries are for a group of people, which have access to the registry.
An example of this kind of registry is the one configured for an organization. This is also called self-hosted registry.
You can choose to place it on your own cloud or use external services such as Google Cloud or AWS.

Before pulling or downloading an image from registry, you need to login into the registry using below command

docker login

If you do not specify a registry URL, it defaults to DockerHub.

To login to private registry or any other than DockerHub, specify its URL after the command as

docker login 127.0.0.1:9090

After logging in, all docker pull commands will search this registry only.

Conclusion

In conclusion, pulling images in Docker is an essential step in the process of setting up and running containers.
By using the docker pull command, we can easily retrieve images from the Docker registry and use them to build and deploy our applications.
The Docker registry serves as a central hub for storing and distributing Docker images, allowing developers to access a wide range of pre-built images for their projects.
By following the outlined steps and best practices, we can streamline our development process and ensure that our containers are running with the necessary dependencies and configurations.
So, next time you’re setting up your Docker environment, remember to pull images from the Docker registry for a seamless and efficient container deployment experience.