Loading
We are going to work with Docker images and how to pull a docker image would be our first step. A Docker image consists of multiple layers. When we pull a Docker image, it actually pulls all the layers associated with it. The Docker images can reuse those layers if you want to pull another image with a different tag. When we use the docker pull
command, it downloads the image locally on your system. After that image is pulled, you can run it to fire up a container.
If you haven’t installed Docker and don’t know much about it, please go through the following quick guides. You must have an idea about all the important terms used in this article.
So, are you ready?
Let’s explore the docker pull
command and learn how to pull a Docker image.
It’s as simple as:
docker pull nginx
It will pull the NGINX image from the Docker Hub locally on your Linux machine. NGINX is a high-performance load balancer and a web server. We can use multiple options in the docker pull command but first, we need to learn the basics. The actual docker pull command is like this:
docker pull image_name:tag
If you don’t give an image any tag while pulling it, it will use the “latest” as the default tag like in the example given below.
Here, I am pulling an NGINX image. By default, it is downloading the image with the “latest” tag.
To confirm the image download, execute the following command:
docker images
You can see the NGINX image is downloaded with an image ID and a tag.
So, whether you run:
docker pull nginx
OR
docker pull nginx:latest
It will download the same image with the latest tag. However, if the tag different, you have to specify it every time in the docker pull
command.
A Docker Image tag tells us useful information about a specific image. It can be the image version or variant. In order to better understand the image tagging, log in to the Docker Hub and search for Nginx. You’ll find hundreds of images with different tags. Each image will have its own pull command that you’ll find against its tag. Copy the docker pull
command with its tag and that specific image will be downloaded.
Let’s try another NGINX image with any other tag. I am trying out the following image that is pulled with the following command:
docker pull nginx:perl
During the pull, if a certain image layer has been pulled already, it means it already exists. The Docker Engine pulls the other layers saving disk space and bandwidth. That’s the most beautiful part of pulling images.
Now there should be two NGINX images with 2 different tags.
Is that correct?
Let’s confirm with the docker images
command.
I hope now you have an idea about image tags. Search for some other images, change their tags and repeat the Docker pull image drill.
Whenever an image is pulled, you’ll find the Digest of that image at the end. It starts with the SHA256 hash of the image’s JSON configuration object. For instance, this is the Digest of the Ubuntu latest Docker image.
Digest:sha256:376209074d481dca0a9cf4282710cd30a9e7ff402dea8261acdaaf57a18971dd
You can find each image’s digest in Docker Hub. So, there are basically three columns for any image.
The digest is different if the operating system has a different architecture. Pulling an image with the digest allows you to pull a fixed version of an image. If you don’t want your images to be updated to the newer versions, use the digest method for pulling images.
Click on the digest and you’ll get the full hash to pull the image.
So, I have copied the following hash to download the Ubuntu image using the digest.
sha256:376209074d481dca0a9cf4282710cd30a9e7ff402dea8261acdaaf57a18971dd
Run the following command to pull the Docker image using the digest.
docker pull [email protected]:376209074d481dca0a9cf4282710cd30a9e7ff402dea8261acdaaf57a18971dd
Write the username ubuntu at the start of the hash otherwise, it will ask for the Docker login credentials.
Finally, that’s how we pull the images with the digest from the Docker Hub. Run the docker images
command to verify the pull.
A Docker image can have hundreds of tags. We can pull all those images with a single command. Let’s try out and pull all the images of Alpine Linux. Alpine Linux is a security-oriented and lightweight Linux distribution.
Here is the command:
docker pull --all-tags alpine
It has started pulling all the images of Alpine Linux. You can see the Digest of each image. This command will take some time to complete.
Run the docker images
command and see the magic.
Alpine Linux is a lightweight distribution with a size of only 5MBs. Using the –all -tags option has downloaded all the images stored on the Docker Hub. You can see most of the Alpine images have a version as a tag. Therefore, we can use tags for image versioning as well.
Finally, I hope you have a better idea now to pull a Docker image. I would strongly recommend going through each command and run it. Also, change the images, try different tags and see the output.
If you have any questions or issues, feel free to let me know in the comments.
Happy Docking!!!
Are you getting too late to Start a Blog in 2021?
Well, I am here to help. Here on this blog, you will find the Best Web Hosting for a startup blog. Learn about WordPress and SEO Basics to kick off your next Business Blog.