How to pull and push images to Docker Hub
Whenever you are working with Docker, you must know two important commands that are how to pull and push images to the Docker hub. In this short article, I’ll describe the necessary commands that will be used to pull and push images to the Docker Hub.
Pull command
In order to pull an image from the docker hub, run the following command:
[root@instance-20191018-2102 ~]# docker image pull <image_name>:<tag>
For Example:
[root@instance-20191018-2102 ~]# docker image pull cenots
If you don’t specify the tag name while pulling the image, the docker will pull the image with the default tag i.e latest. To pull the image of a specific tag run the following command:
[root@instance-20191018-2102 ~]# docker image pull centos:8
By default, the pull command pulls the image from the docker hub. In case you want to pull the images from other registries Google Container Registry (GCR), Amazon Elastic Container Registry (ECR), etc, you have to mention the registry name. Below is the syntax to pull images from other registries:
[root@instance-20191018-2102 ~]# docker image pull <registry>/<repository_name>/<image_name>:<tag>
For example: to pull the Nginx image from Amazon ECR, run the following command:
[root@instance-20191018-2102 ~]# docker image pull public.ecr.aws/runecast/nginx:1.21.1-alpine
Push command
To push the images to the Docker hub, run the following command:
[root@instance-20191018-2102 docker]# docker push <repository_name>/<image_name>:<tag>
For example:
[root@instance-20191018-2102 docker]# docker push techsupper/centos:v1
In the above example: techsupper is the repository name which is created by me on the docker hub.
You have to login into the docker hub account before you push the image. Use the following command to login into the docker hub:
[root@instance-20191018-2102 docker]# docker login
Look at the complete video to know all the commands step by step:
Further readings
Know about all commands of the Docker images
What are Docker images and their layers
How to create a docker container
Architecture and basic terminologies of Docker
How to create an NGINX docker container
Know about all commands of the Docker container
You can subscribe to my YouTube channel for further reading.