Searching and pulling Docker Images from Dockerhub


The official Docker registry contains a lot of pre-built images and publicly available customized images that are very useful and can be easily pulled by the users in their local machine and used as base images for their projects. In fact, you can also build your own customized docker image using one of those publicly available docker images and push it back either in a public or private mode.

In this article, we will discuss how to search for a docker image using the search command through the command line interface. We will also see how to filter the search results based on certain parameters. After that, we will see how to pull those images and list all the pulled images in your local machine using the docker pull and list commands.

To start building a container or an image, we need to specify a base image in our dockerfile so that on top of that base image, we can build our own customized image layers and install packages, libraries and much more. These base images are available in the official docker registry which is called the dockerhub. To use that, you need to have an account created on dockerhub and you need to be logged in to that account through you command line using the docker login command. It will ask you for username, email and password for you to log in. After that, we can search for our base image using the docker search command. You can use the command below to do so.

sudo docker search <term>

In place of the term, you need to enter the name or a keyword related to that image, in order to generate a list of similar images available on dockerhub.

For example, to search for an ubuntu image, you can use the following command.

sudo docker search ubuntu

To search for a busybox image, you can use −

sudo docker search busybox

The output of the search command will contain a list of images relating to the search term along with other parameters such as name, automated, stars, description, official.

The name field contains the name of the image, the description field contains a short description about the image, star parameter contains the number of stars given by the users, the official parameter specifies whether the image is official or from a trusted source or not and the automated features tells you whether or not you can build the image automatically with a github or bitbucket push

You can also filter your search results using the filter option in your docker search command.

For example, if you want to find the list of images relating to the search term which has a minimum 20 stars, you can use the following command.

sudo docker search −−filter=stars=30 ubuntu

If you want to find a list of images relating to your search query with a filter that the automated parameter should be true, you can use the following command −

sudo docker search filter=is-automated=true ubuntu

To know more about the docker search command, you can always use the help option with command

sudo docker search −−help

After you have your image name with you, you can pull the docker image using the following command.

sudo docker pull <image−name>:<tag−name>

Here, the tag−name specifies an image with a particular tag given to it. If you don’t specify the tag name, it will automatically pull the latest published image. For example, you can use python with a tag 3 to pull python 3 image or you can use centos with a tag 7 to pull centos 7 image.

An example of the docker pull command is −

sudo docker pull python:3
sudo docker pull ubuntu

If you want to pull all the tagged images associated with an image name, you can use the −−all−tags option along with the pull command.

See the example below.

sudo docker pull −−all−tags python

To list all the images that you have pulled in your local machine from the docker registry, you can use the following command.

sudo docker images

The above command will generate a list of all the images running in your local system along with the tag name, the image ID, the size of the image and the date of creation.

To conclude, using a filtered search method to generate a list of all the available docker images in the official docker registry gives you an idea to choose the best image and you can also sort out the images based on the number of likes or stars it has received from its users worldwide. Also, tagging an image gives you an idea of the latest version of the image or the latest feature that has been embedded into it, so that you can get the most recent or the updated image for your personal use. Thus, dockerhub provides a one stop shop for all the docker users to get a plethora of official base and/or customized images publicly available for all.

Updated on: 27-Oct-2020

305 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements