Docker has tons of official and vendor-specific images hosted on its own cloud registry called Docker Hub. If you are a registered user in Docker Hub, you can leverage it to pull or download several useful Docker images from it such as Nginx web server, Ubuntu, Centos, Fedora, MySQL, Python, Alpine, Java, etc. You have to be logged in to Dockerhub using the command-line to issue the Docker pull command. When we try to use the Docker run command on a particular image, if the daemon does not find the same image already existing in your local machine, it will pull it straight from the Docker registry. Also, when creating a Docker image using Dockerfile, the base image is downloaded from the public registry called hub.docker.com. Apart from all these options, we can also use the Docker pull command to directly download any Docker image from the Docker registry to our local machine. As discussed, there are tons of pre-built images available on Docker Hub that we can pull and we don’t even need to configure or define them. We can use them either as it is by creating a container associated with them or use them as base images to create new layers on top of them.
Docker Pull Command
Let’s see the general syntax of the Docker pull command.
$ docker pull [OPTIONS] IMAGE_NAME[:TAG|@DIGEST]
In the above command, we can specify several options along with the Docker pull command. Some of them are -
|Name or shorthand notation||Default value||Description of the option|
|--all-tags , -a||It lets you download all the tagged images of that particular image name in the repository|
|--disable-content-trust||true||You can skip verification of the image.|
|--platform||If your server is multi-platform, then you can set it.|
|--quiet , -q||It allows you to suppress the progress or verbose.|
We can optionally specify the tag or digest of the image along with the image name. Let’s see a few examples of how we can use the Docker pull command to pull or download images from the Docker registry.
Example 1. Pulling an image
Let’s try to pull the ubuntu image directly. If we don’t specify a tag with the image name, it will pull the image with the latest tag by default.
$ docker image pull ubuntu
Let’s verify the download by listing all the images.
$ docker images
We can see that our ubuntu image with the latest tag has been downloaded successfully.
Example 2. Pulling an Image with a tag
Let’s try to specify a tag along with the image name.
$ docker pull ubuntu:18.04
Here, we want to pull the ubuntu version 18.04 from Dockerhub. Let’s list all the images to verify. You can see that the ubuntu image with version and tag 18.04 has been downloaded.
Example 3. Pulling images by digest
We can also pull Docker images by specifying their digests. When we are pulling a Docker image by specifying their digests, we specify the same exact version that we want to pull. We can specify the digest along with the image name separated by @ symbol. You can check the digest of the image when you pull one. For example, when we pulled the ubuntu image with tag 18.04. It displayed the digest along with it. Let’s check it out. Let’s pull the same image by specifying this digest.
$ docker pull ubuntu@sha256:4bc3ae6596938cb0d9e5ac51a1152ec9dcac2a1c50829c74abd9c4361e321b26
Example 4. Pulling an entire repository with multiple images
Let’s try to use the --all-tags option to pull all the images named fedora from the fedora repository in the Dockerhub registry.
$ docker pull --all-tags fedora
Let’s list all the fedora images in our local machine. You can see that we now have pulled all the tagged fedora images available in the fedora Dockerhub repository.
Example 5. Pulling an image by suppressing the verbose
You might have noticed that when we pull images from the Dockerhub, it shows the entire progress such as layer-by-layer pull, image digest, status, the location from where it has been pulled, etc. If you don’t want these details to be printed in your terminal, you can use the --quiet option to suppress the verbose.
$ docker pull --quiet busybox
You can see that this time the Docker daemon pulled the image quietly.
How does the Docker pull command work?
When we execute the Docker pull command inside the terminal, the Docker daemon searches the local host machine for the same image. If such an image already exists on your local machine, it won’t pull the same image. Otherwise, it connects to the link “hub.docker.com” which is a public Docker registry. It connects to it only if you have not specified any private registry in your “daemon.json” file. After that, the daemon will pull the specified image with the specified tag or digest from the registry. If it finds the image locally, it will look for a newer version or update the image and download it. Behind the scenes, the digests of the images are compared. Please note that, as already discussed, if we don’t mention any tag or digest with the image name, by default, the daemon is configured to pull the image with the latest tag which often refers to the latest version of the image. If you try to access a registry behind a server proxy, you will need to configure the daemon’s settings for proxy with the help of env variables using systemd.
Advantages of using the Docker pull command
Let’s discuss a few advantages of using the Docker pull command.
- You can download pre-built images either from a private or a public registry.
- You can even pull the entire repository by specifying the --all-tags option.
- You can even download unsigned images, however, you need to be careful as it may cause a threat to your system.
The Docker pull command is one of the most frequently used commands in Docker. Hence, it’s very important to know how to use it and get hands-on with all the important options that it allows us to use with it. In this guide, we discussed a basic introduction to the Docker pull command and how to use it along with several options such as quiet, all-tags, etc. to pull Docker images by specifying name, tags, and digests. We hope that using this comprehensive guide, you will be able to get hands-on with the Docker pull command. Happy Learning! People are also reading: