Open In App

Docker Push

Last Updated : 07 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

By pushing an image to the DockerHub registry, we can create an instance of an image in which a particular type of software and applications are pre-installed and can be pulled again whenever you want to work on that particular type of image or application and run that kind of virtual machine. In the DockerHub there are millions of images you can also pull the default images which are created by particular organizations for example you can pull the Ubuntu image which is uploaded by Linux, and then install any software or application into that image like curl command, Jenkins, etc and then push that docker image to your docker hub registry. 

Docker Push

Docker push is a command which is used to push the docker images to the docker Private/Public registries. After building the customized docker image you need to push it to the remote registries from where other developers or DevOps engineers can access the image and work on it to push the image you can use the docker push command. It is an important step to perform because if you store it locally others can’t access the image but if it is available remotely others can access it.

Docker Push Command

Docker push commands requires two arguments to push the command into the registry.They are

  1. Name of the Docker image.
  2. Nmae of the registry to push the image.

Example:

If you want to push an image with the name as GFG-Image to the GFG-DockerImages repository which is located in the dockerhub registry then you will use the following command.

docker push GFG-Image GFG-DockerImages 

docker push <Name of the image> <Name of the repo>

In the place of <Name of the image> replace with your image name and in the place of <Name of the repo> replace with the your repository name.

Dockerfile HUB

The way of building an docker image with the help of Dockerfile and publishing that Docker images to Docker Hub is known as Dockerfile HUB. A cloud-based registry for Docker images is called Docker Hub. Millions of developers and organisations use it as the biggest public registry for Docker images, storing and exchanging their images. To know more about Dockerfile refer to the Concept of Dockerfile.

Build the docker image by using the dockerfile and push the docker image with the help of following command.

docker push <name of the image>

Pull Docker Image

You can pull any type of docker image by using the command docker pull. Along with the command you need to mention the image name that you want to pull for example

If i want to pull the docker image nginx then you use the command.

docker pull nginx 

You can use different other flags with the command like — flag name of the flag.

Docker Push Local Image Push Image To Docker Hub

Following are the steps to push a new image to a registry:

Step 1: The first step is to give a tag to your docker image which is a reference to your docker image ID which conveys the information regarding the image version. If you log in to your docker hub account and search for a standard image of MySQL, HTTP, etc there you notice these tags. To build a customized image you need to write a customized Dockerfile.

docker image tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

If you do not mention the tag then the default tag is the latest. For example,

docker image tag ubuntu:14.04 XYZ/ubuntu:2.0
Docker image tag

Command to tag an image

Ubuntu is a source image in our docker container 14.04 is the tag to that source image.XYZ in the target image name has to be similar to your docker hub account username and the tag is 2.0.     

Step 2: Now if you try to push the image then it will give an error:

denied: requested access to the resource is denied

The reason is that for pushing the image in your docker hub account first you have to log in.   So the second step is to log in to your docker hub account. To login, the command is      

docker login

Docker login

  Now write your respective username and password you give while creating a docker hub account.             

Note: If you are a Mac user after pushing your image do not forget to logout because the authentication key is written to a file to remember you as user of that docker hub account in the future if it is your personal device no need to do this.

docker logout

docker logout

Docker Push Images

Step 3: Now after you login you are able to push the image the command is:

docker image push [OPTIONS] NAME[:TAG]

 For example:

docker image push XYZ/ubuntu:2.0
docker image push

Push command

After running this command your image will be pulled to the docker hub repository.

docker hub repositry

Note: Write sudo before every command if your image is in the root account and XYZ is your username of docker hub account.

Docker Push All Tags Of An Image (-a, –all-tags)

Docker push will push only the latest tags if you want to push all the tags then you need to use -a or –all-tags which will push all the tags of an particular image to registry.

Example

If you use the following command then you can push only the latest tag of docker image to the registry.

 docker push my_image

If you want to push all the tags of docker image then you need tot use the following command.

docker push my-image -a

FAQs On Docker Image Tags

1. What Is Docker Push Verbose

The flag “docker push verbose” can be used in conjunction with the docker push command to show more specific details about the push procedure.

2. How To Docker Push Multiple Images

By using the following command you can push all the docker images at once

docker push -a

3. How To List Docker Images With Tags?

You can use the command mentioned below to see the all docker image tags.

docker image [Repository name]:[Tag] Replace the repository name with the your name and pass the tag you want to see.

Example:

docker images java:10

4. Can Docker Image Have 2 Tags?

Yes you can create multiple tags for the same image which helps us in many scenarios.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads