What is Docker Hub?
Docker Hub is a repository service and it is a cloud-based service where people push their Docker Container Images and also pull the Docker Container Images from the Docker Hub anytime or anywhere via the internet. It provides features such as you can push your images as private or public. Mainly DevOps team uses the Docker Hub. It is an open-source tool and freely available for all operating systems. It is like storage where we store the images and pull the images when it is required. When a person wants to push/pull images from the Docker Hub they must have a basic knowledge of Docker. Let us discuss the requirements of the Docker tool.
Docker is a tool nowadays enterprises adopting rapidly day by day. When a Developer team wants to share the project with all dependencies for testing then the developer can push their code on Docker Hub with all dependencies. Firstly create the Container Images and push the Image on Docker Hub. After that, the testing team will pull the same image from the Docker Hub eliminating the need for any type of file, software, or plugins for running the Image because the Developer team shares the image with all dependencies.
Advantages of Docker
Docker Container Images are light in weight. We can push the images within a minute and with help of a command. It is a secure method and also provides a feature like pushing the private image or public image. Docker hub plays a very important role in industries as it becomes more popular day by day and it acts as a bridge between the developer team and the testing team. If a person wants to share their code, software any type of file for public use, you can just make the images public on docker hub.
How to push or pull images from Docker Hub?
To get started with Docker Hub you should be able to get familiar with the below two commands:
1. Push Command
This command as the name suggests itself is used to push a docker image onto the docker hub.
Implementation: Follow this example to get an idea of the push command:
- Open Docker in your system.
- Locate the Images that you want to push using the below command:
# docker images
The above command will list all the images on your system.
1.1: Go to the browser and search hub.docker.com.
1.2: Sign up on the docker hub if you do not have a docker hub account, after login on to the docker hub.
1.3: Back to the docker terminal and execute the below command:
# docker login
1.4: Then give your credential and type in your docker hub username or password.
1.5: After that hit the Enter key you will see login success on your screen.
1.6: Then type the tag images name, docker hub username, and give the name it appears on the docker hub using the below command:
# docker tag geeksforgeek mdahtisham/geeksimage geeksforgeek - Image name mdahtisham - Docker hub username geeksimage - With this name Image will appear on the docker hub
1.7: Now push your image using the below command:
# docker push mdahtisham/geeksimage
Below you can see the Docker Image successfully pushed on the docker hub:
2. Pull Command
The pull command is used to get an image from the Docker Hub.
Follow the example to get an overview of the pull command in Docker:
2.1: Now you can search the image using the below command in docker as follows:
# docker search imagename
One can see all images on your screen if available images with this name.
One can also pull the images if one knows the exact name
.2.2: Now pull the image see the below command.
# docker pull mdahtisham/geeksimage mdahtisham - Docker Hub username geeksimage - With this name Image will appear on the docker hub
2.3: Now check for the pulled image using the below command as follows:
# docker images