We can directly pull Docker images from any Docker registry using Docker pull command. The Docker pull command allows us to pull images and repositories from Docker registries. We create most of the images using Dockerfiles on top of a base image pulled from the Dockerhub registry. There are tons of free and vendor-specific pre-built Docker images available on Dockerhub. We can directly pull these images and use them without having to configure them on our own.
In this article, we will discuss how to pull Docker images from registries such as Dockerhub. Before we move ahead, check out these articles to better understand the concept.
Log In to Dockerhub
We can use the Docker Pull command to pull Docker images. In order to do so, we first need to create an account on hub.docker.com. Using the credentials, we can log in to Dockerhub through our command line using the Docker login command. It will prompt you to enter your username and password.
$ docker login

Pull Docker Images
Now, we can pull any Docker image from Dockerhub using the Docker pull command. The syntax of the Docker Pull command is –
$ docker pull [OPTIONS] NAME[:TAG|@DIGEST]
We can also use the Docker Image Pull command as well.
$ docker image pull [OPTIONS] NAME[:TAG|@DIGEST]
The options that can be used along with the Docker pull command are –
Name | Shorthand | Description |
--all-tags | -a | To download all the tagged images that are available in the repository. |
--disable-content-trust | To skip the verification of the images. | |
--platform | Used to set a platform if the server is capable of running multiple platforms. | |
--quiet , -q | -q | It is used to suppress the verbose output. |
Now, we will see a few examples to demonstarte the full potential of the Docker pull command.
Docker Pull Command
We can use the Docker Pull command to download a particular image or repository from the Dockerhub registry. A repository is a set of images. If we don’t provide any tag along with the image name in the Docker pull command, then it automatically uses the latest tag by default. Let’s try to pull the busybox:latest image.
$ docker pull busybox:latest
When we pull the Docker images from Dockerhub, the daemon first compares the image digest with all the existing images in the host. If a match is found, then it uses the already existing image, If no match is found, it will start pulling the image from the registry.

Let’s try to verify the image pull by listing all the images.
$ docker images

You can see that we have successfully pulled the busybox:latest Docker Image.
Docker images are build using multiple intermediate layers. These layers can be reused when we pull newer images from Dockerhub later on. For example, if we have pulled an Ubuntu image with tag 18.04 and later on, we need to pull another image with the latest tag, then the new pull can use layers from the already existing Ubuntu image if required. This is possible through build cache.
Pull an Image by Digest
Each Docker image has a content-addressable identifier which is unique for all of them. This is called Image digest. An image digest is used when Docker tries to find if an image already exists in the host or not. When we pull an Ubuntu:20.04 image from Dockerhub, it pulls the latest version of this image. But if we don’t want it to pull the latest version, then we can specify the digest of the specific Ubuntu:20.04 image that we want to pull.
Let’s see how to do so. First, we will print the digests of all the existing images.
$ docker images --digests

Now, we will try to pull the Ubuntu image with the latest tag but using the digest of the image.
$ docker pull ubuntu@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93
Since, the image already exists, it will use the build cache to simply update the metadata of the image and will not pull the image again.

Pull a repository with all the Images
A repository is a set of similar images. To pull all the images from a repository, we can use the –all-tags option along with the Docker pull command. We will try to pull all the fedora images from the fedora repository.
$ docker pull --all-tags fedora

To check if the entire repository has been pulled or not, we can list all the fedora images.
$ docker images fedora

You can see that all the images have been pulled successfully.
Final Thoughts!
In this article, we discussed how to pull Docker images from Dockerhub. We saw the syntax of the Docker pull command along with the options that we can use with it. Next, we discussed how to pull Docker images using the name, tag, digest, and also pulled a complete repository.
We hope that you have now gained in-depth knowledge to pull images from Dockerhub. If you have any queries or suggestions, please mention them in the comments and we will have our experts get back to you. Also, check out our complete and free Docker Tutorial.