Docker is a very powerful tool to containerize the application. It is now one of the best choices when it comes to containerizing your application. This tutorial will learn how to find and use the available docker images. We will also go over a few basic terminologies used in the container world. Before going deep dive into available images, let’s first understand what docker images are.
What is a docker image?
An image is a template to create docker containers. A docker image is created using a text file called a Dockerfile. A Dockerfile is nothing but a well-defined syntax.
Please refer to the below diagram to understand how to create a docker image.
Where to find the docker images
The Docker hub is where you can find all the available docker images. It is a service provided by Docker for finding and sharing container images, and it is the largest repository of container images. It contains community developers, open-source projects, and independent software vendors (ISV) images.
Docker hub provides free access to public repositories to store and share images with other people. It also provides a facility to host private images in private and public repo.
But there is a limit to the number of the private repo you can have in the free version of Docker, and currently, you can have only 1 private repo in dockerhub.On the other hand, you can have as many public repo as you want.
List of available images in dockerhub
To see the list of available images, go to the docker hub.
Click on explore and go to the docker tab.
As you can see in the above screenshot, there are currently 6.4 lakh images available. You can filter out the images from the verified publisher and the official publisher.
Now let’s search the Nginx image in the dockerhub and understand its components.
Here you can see we got more than 80k results for Nginx images. If the image is official, you can see a tag for Official Image in the top right corner. You can also see how many times the images are downloaded, the rating given, and when the images are updated.
What are official images?
Docker official images are the ones that professional writes by promptly ensuring the best practices and applying security updates in such images. If you are new to Docker, it is highly recommended to use the official images in your project as much as possible.
Now let’s click on the Nginx official image and understand the layout.
In the descriptions tab, you will find information about the image, like what Nginx is and how to use this image, etc.
If you want to know how this image was written, click on any supported tag, and its respective docker file will be opened. You can look at the code and understand how the Dockerfile has been written.
Verified publisher images in dockerhub
Besides the official images, dockerhub also has images from the verified publishers. These images are maintained directly by commercial vendors. Some of the most popularVerified publishers are:-
- Amazon, etc.
These vendors continuously update their images and scan them for vulnerability before uploading them to dockerhub.
If possible, try to use either the official image or the images from the official vendors because these images are of high quality and lessvulnerable than other available images.
How to use an image from the dockerhub
Now we have a clear idea about where to find the images, now let’s go deep dive and understand how we can use the available images.
Setup docker in your computer
Download the Docker from download docker based on your operating system version. Let’s verify if the installation is OK.
Type docker –version to see the docker version installed.
➜ ~ docker --version Docker version 20.10.3, build 48d30b5
Check all available images by typing the below command.
➜ ~ docker images REPOSITORY TAG IMAGE ID CREATED SIZE
If the Docker is newly set up, there will be no images by default.
Now let’s pull a simple hello world image from the docker hub
➜ ~ docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519 Status: Downloaded newer image for hello-world:latest docker.io/library/hello-world:latest
If you do not specify any tag, it will pull the latest image from dockerhub
Now verify if the image was pulled successfully.
➜ ~ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d1165f221234 8 weeks ago 13.3kB
Now let’s run this image.
➜ ~ 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 the same o/p as mentioned here, it means your image is working as expected.
This was just a basic example of how to pull a hello-world image from the dockerhub. Please go ahead and try to pull other images from the dockehub. Almost all the verified vendors provide instructions on how to pull and use their image
Congratulations, we now have a basic idea about docker images and what images are available in the docker hub. We have also pulled a basic hello-world image from the dockers. This is just the beginning of the docker world. Docker is a powerful tool, and almost all companies use Docker to deploy their application in production.