Pushing an image to Docker Hub

The goal of creating a Docker image that contains an application is to be able to use it on servers that contain Docker and host the company's applications, just like a VM.

In order for an image to be downloaded to another computer, it must be saved in a Docker image registry. As already mentioned in this chapter, there are several Docker registries that can be installed on-premise, as in the case for Artifactory and Nexus Repository.

If you want to create a public image, you can push it (or upload it) to Docker Hub, which is Docker's public (and free) registry. We will now see how to upload the image we created in the previous section to Docker Hub. To do this, it is a requirement to have an account on Docker Hub, which we created just before installing Docker Desktop.

To push a Docker image to Docker Hub, perform the following steps:

  1.  Sign in to Docker Hub: Log in to Docker Hub using the following command:
docker login -u <your dockerhub login>

When executing the command, it will ask you to enter your Docker Hub password and indicate that you are connected, as shown in the following screenshot:

  1. Retrieving the image ID: The next step consists of retrieving the ID of the image that has been created, and to do so we will execute the docker images command to display the list of images with their ID.

The following screenshot shows the retrieval of the ID of the image:

  1. Tag the image for Docker Hub: With the ID of the image we retrieved, we will now tag the image for Docker Hub. To do so, the following command is executed:
docker tag <image ID> <dockerhub login>/demobook:v1

The following screenshot shows the execution of this command on the created image:

  1. Push the image Docker in the Docker Hub: After tagging the image, the last step is to push the tagged image to Docker Hub.

For this purpose, we will execute the following command:

docker push docker.io/<dockerhub login>/demobook:v1

The following screenshot shows its execution:

We can see from this execution that the image is uploaded to Docker Hub.

To view the pushed image in Docker Hub, we connect to the Docker Hub web portal at https://hub.docker.com/ and see that the image is present, as shown in the following screenshot:

By default, the image pushed to Docker Hub is in public mode – everybody can view it in the explorer and use it.

So, we can access this image in Docker Hub in the Docker Hub search engine, as shown in the following screenshot:

To make this image private – that is, you must be authenticated to be able to use it – you must go to the Settings of the image and click on the Make private button, as shown in the following screenshot:

In this section, we looked at the steps and Docker commands for logging in to Docker Hub via the command line, then we looked at the tag and push commands for uploading Docker image to Docker Hub.

In the next section, we will see how to deploy this image with a CI/CD pipeline in a managed cloud container service – ACI and Terraform.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.102.182