what docker pull does

What docker pull does | Complete tutorial for beginner [2022]

In this blog, I will be explaining what docker pull does, and we will see a couple of practical demonstrations of the docker pull command. We will also understand what image digest is and where the docker images get saved. So before going deep dive into the docker pull command, let’s first understand a few basic terminologies.

What is dockerhub?

Dockerhub is the world’s largest repository for container images. In Dockerhub, you will find images from the developer, open-source contributors as well as official images. You can even create your images and push them to dockerhub.

In dockerhub, you can create public and private repo’s to push your docker images. Dockerhub provides lots of advantages, some of them are:

  • You can easily push and pull images anytime.
  • You have the flexibility to create a private repo to store your customized images.
  • You can pull high-quality images from the official vendors.
  • You can pull images from external vendors as well.
  • You can create an organization and add your teammates.

How to find the images in the docker hub

To find the available images in the docker hub, goto Dockerhub

dockerhub

On the search bar, search for any images. let’s search for the Nginx image

dockerhub

As you can see, we have more than 8k images available for Nginx. It is always recommended to use official images.

Now we have a pretty good idea about how to find images in Dockerhub. Now let’s proceed further to understand what docker pull does.

What docker pull does?

Docker pulls basically pulls an image or a repository from a registry. Docker will pull an image from the docker hub if you do not specify any registry. While pulling images, you have the flexibility to select the version as well. If the version is not specified docker pull command will always pull the latest image.

Now let’s proceed further and see the syntax of the docker pull

syntax

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

There are many options available for image pull. To get a list of options, type.

➜  ~ docker pull --help

Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from a registry

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is multi-platform capable
  -q, --quiet                   Suppress verbose output
➜  ~

docker pull hello-world

In this session, we will be pulling a hello-world docker image from the dockerhub. Before proceeding further, make sure the docker is installed in your system and is running.

Now let’s pull the hello-world image from the dockerhub

docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Image is up to date for hello-world:latest
docker.io/library/hello-world:latest

The above command will download the hello-world image from dockerhub to your local system. Run the below command to verify if the image gets successfully pulled.

docker image ls
REPOSITORY                     TAG              IMAGE ID       CREATED         SIZE
hello-world                    latest           d1165f221234   3 months ago    13.3kB

What to do after docker pull?

Once you have pulled an image from the dockerhub, the next step is to run the image using the docker run command. The run command creates an isolated container that runs on your host machine.

Let’s run the hello-world image which we pulled earlier

➜  ~ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
``

If you are getting output as Hello from Docker! It means your hello-world image is working as expected.

The hello-world image was a basic image to verify the docker setup. Now let’s pull another image from the dockerhub and run it using the docker run command.

Pull an nginx image

In this session, we will be pulling an Nginx image from the dockerhub. More information about the Nginx image can be found here.

Run the below command to pull an Nginx image

docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Already exists
30afc0b18f67: Pull complete
596b1d696923: Pull complete
febe5bd23e98: Pull complete
8283eee92e2f: Pull complete
351ad75a6cfa: Pull complete
Digest: sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

Verify if the image is by running the below command:

docker images
REPOSITORY                     TAG              IMAGE ID       CREATED         SIZE
nginx                          latest           d1a364dc548d   3 weeks ago     133MB

Let’s run the Nginx image and forward the request to port 8080

docker run --name mynginx -d -p 8080:80 nginx:latest
ecdefe6d6e2661e8fc44a13d4f036fefefd2959658fa79c24d74eafe075bcd3a

goto http://localhost:8080 to access the Nginx web UI

what docker pull does

If you are getting the above page, it means your Nginx setup is working as expected.

Let’s run the below command and check if there is any container that gets created for the Nginx image

docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                  NAMES
ecdefe6d6e26   nginx:latest   "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes   0.0.0.0:8080->80/tcp   mynginx

There is one container named mynginx that is running for Nginx installation.

Now we understand how to pull an image from the public dockerhub repo, let’s proceed further and understand how to pull an image from a private repo.

docker pull from a private repo?

To pull an image from the private repo, first, you need to login into your git repo with your credentials.

docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: naiveskill
Password:

Once you are logged in, you can run the below command to pull the image from the private repo.

docker pull myrepo/myimage

You can also specify the tag while pulling the image

docker pull myrepo.com/myimage:tag

I hope now you are comfortable with pulling and running a docker image. In the next session, we will understand another important concept related to docker pull which is image digest

docker image digest

Docker containers are basically present in the form of [namespace/] followed by a tag. Docker digest is provided as a hash of a Docker image supported by the Docker v2 registry format. Thesha256 generates the hash and is deterministic based on the image build.

So instead of passing the image name, docker images can be directly run using digest

To list down the image digest, type the below command:

docker images --digests
REPOSITORY                     TAG              DIGEST                                                                    IMAGE ID       CREATED         SIZE
nginx                          latest           sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750   d1a364dc548d   3 weeks ago     133MB

Now let’s try to run this image using digest

docker run --name mydigestnginx -d -p 8081:80 nginx:latest@sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
a4f6e3db8597712b9e6c9a3f17cda55c87a1fe259af56183080859fe182d5fed

go to http://localhost:8081 to access the Nginx web UI.

To get more information about the image digest, go to this link.

where does docker pull stores images?

When you pull an image from the dockerhub, the images will be downloaded into your system and reside in memory. The next question that might come to your mind is where the images get stored on a hard disk.

So the images stored in your system are based on the OS on which the docker is running. Please find below the image path for different operating systems:

Ubuntu: /var/lib/docker/
Fedora: /var/lib/docker/
Debian: /var/lib/docker/
Windows: C:\ProgramData\DockerDesktop
MacOS: ~/Library/Containers/com.docker.docker/Data/vms/0/

Conclusion

I hope you have found this article useful. We have started with the basics of dockerhub, and we deep dive into the docker pull command. We also pulled and ran hello-world and Nginx images from the dockerhub. And finally, we understood what image digest is and where the docker images save on disk. Please do let me know in the comment box if you need more clarification on any topic.

More to read?

Docker layers

Which docker base image to use

What docker images are available

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top