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?
- Beginner’s Guide for Docker Hub and Docker Registries
- How to Pull Docker Image From Docker Registry?
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”:
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:
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”:
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:
Step 7: Run Docker Image
Now, execute the Docker image to run the Docker container:
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:
To create a target image, utilize the provided command:
List down all images and verify whether the image is created or not:
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:
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:
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:
Again, list down all Docker images to confirm if the image is downloaded from the Docker Hub registry or not:
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.