Docker

Docker Hub and Docker Registries Beginner’s Guide

Docker is a well-established service product platform used to deliver the project and software in the form of Containers. It can also be utilized to develop and deploy applications. For this purpose, Docker uses OS-level Virtualization. Moreover, the major components of the Docker platform are Docker images, Docker containers, Docker registries, and Docker engine that provide services on the Docker server and the local machine.

This post will discuss:

What are Docker Hub and Docker Registries?

Docker registries are the storage used to store, manage and distribute Docker images. The registries can be of two types: local registry and remote registry. The Docker Hub is an official cloud base registry of Docker that hosts Docker images. It stores and manages Docker images with images name and tag versions.

Beginner’s Guide for Docker Hub and Docker Registries

Docker Hub is an official registry of the Docker platform. Look at the provided procedure to utilize the Docker registry to maintain and store the Docker images.

Step 1: Open Docker Hub Docker Registry

First, navigate to the Docker official registry Docker Hub and click on the “Sign In” button. If users do not have a Docker Hub account, then register by clicking on the “Register” button or utilizing the below highlighted “Get Started Today for Free” menu:

Step 2: Provide User Account Credentials

Provide your credentials, such as “Username or Email” and “Password” to log in to your Docker Hub Account. After that, press the “Continue” button:

Here, you can see we have successfully login to Docker remote registry “Docker Hub”:

Alternatively, users can log in to the Docker registry with the help of the terminal. To login to the Docker registry, utilize the “docker login” command and provide “hostname/username” and “password”:

$ docker login

The output indicates that we have successfully logged in to the Docker registry:

Currently, there exists no Docker image in the Docker Hub repository:

Step 3: Open Visual Studio Code Editor

Open the Visual Studio Code Editor via “Startup” menu:

Step 4: Create Simple Dockerfile

Create a simple Dockerfile and paste the following code. This code will generate a Docker image to execute a simple “Tutorial.py” Python program:

FROM python:3.6
WORKDIR /src/app
COPY . .
CMD [ "python", "./Tutorial.py" ]

Step 5: Create Simple Python Program

Create a new file “Tutorial.py” and paste the provided code. The mentioned code will print “Hello, Welcome to Linuxhint Tutorial”:

print("Hello, Welcome to Linuxhint Tutorial")

Step 6: Build Docker Image

Next, open the terminal in the Visual Studio editor and execute the given command to generate a new Docker image. Here, the “-t” option is used to specify the name of the image:

$ docker build -t python-image .

Step 7: Run Docker Image

Now, execute the Docker image to run the Docker container:

$ docker run python-image

The output shows that we have successfully built and deployed a Python program:

Step 8: Generate Target Image

Create a target image that will be pushed to the Docker registry. The syntax for creating a target image:

docker tag <source-image> <hostname/username>/<target-image>:<version/tag>

To create a target image, utilize the provided command:

$ docker tag python-image rafia098/python-image:3.6

List down all images and verify whether the image is created or not:

$ docker images

It can be observed that we have successfully generated the target image:

Step 9: Push Image to Docker Official Registry

Push the image to remote Docker registry through “docker push” command:

$ docker push rafia098/python-image:3.6

Here, you can see we have successfully pushed the Docker image in the Docker Hub cloud registry:

How to Pull Image From Docker Registry?

The process of pulling an image is downloading the image from the cloud registry to the local registry or repository. The “docker pull” command is used to download or pull the public Docker image as shown below:

To pull the Docker image from the Docker Hub registry, go through the given instructions.

Step 1: List All Images

To list down all local Docker images, utilize the provided command:

$ docker images

Step 2: Pull Docker Image From Docker Hub

To pull the Docker image from Docker Hub, execute the “docker pull <username>/<image-name>:<tag>” command as follows:

$ docker pull rafia098/python-image:3.6

Again, list down all Docker images to confirm if the image is downloaded from the Docker Hub registry or not:

$ docker images

The output shows that we have successfully pulled the Docker image from the Docker registry:

We have provided the beginner guide on Docker Hub and registries.

Conclusion

Docker Hub is an official remote or host Docker registry that is used to store, manage and share Docker images. To push the Docker image from the local registry or repository, utilize the “docker push <username>/<image-name>:<tag>” command. In order to pull the Docker image from the Docker official registry Docker Hub, use the “docker pull <username>/<image-name>:<tag>” command. This post was a complete guide on Docker Hub and registries for beginners.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.