In this article, you’ll understand how to push our extended images to a Docker repository, so that other developers can use that image or we can pull that to our production environment and run it as a container. Please, read our previous article before proceeding to this article where we learn how to Create a Containerized .NET Core Web Applications.
In the previous article, we have learned how to build a Docker image either by manually committing the changes we made in a container or by writing a Dockerfile.
The easiest way to make your images available is to use the Docker hub which provides free repositories for public images. So, before that, we need to create a Docker hub account.
Let’s go to Docker hub, where you sign up for your account. visit this link https://hub.docker.com
Just type your Docker hub ID, email address, and password. After you have signed up and you have logged into your account. It looks like this.
we have just created a Docker hub account for this tutorial. Monktutorial is the Docker hub ID.
In order to push the image to the right repository, we need to associate the image with a Docker hub account. The way to link the image with a Docker hub account is to rename the image to something like.
The command to rename the image is a docker tag.
Let’s see this in the below example. First, we issue the docker images command which displays all the current images in my local box. The image we are going to push is this extended Debian image.
Now, let’s rename this image. then type docker tag, copy and paste the image ID. Then the repository name, Monktutorial/Debian, We also need to specify a tag for this image.
If we leave it blank, then Docker will use the default latest tag. But try not to use the latest tag unless you have to.
Docker will use the latest as a default tag when no tag is provided. But beyond that, the latest tag has no special meaning. A lot of repositories use it to tag the most up-to-date stable image. However, this is still only a convention and it is entirely not being enforced.
Images that are tagged latest will not be updated automatically when a newer version of the image is pushed to the repository.
If you are shipping Docker images to a production environment, you should ignore the latest tag. Don’t use it. Don’t be tempted by it. It’s easy to look at it and think that your deployment script should pull “latest”.
Docker Tag with Version
However, this is not enforced. It takes a lot of direction to make that work. The safest way is to version your tags every time.
Here, we just explicitly specify tag 1.01.
Then execute the command. Now, let’s see the docker images again.
As you see, The image has been tagged with the new name. The first and the second image have the same image ID because they are the same image and have exactly the same content, but tagged with different names.
Push Image on DockerHub
The next step is to push the image to the DockerHub. In order to do this, we need to issue the command docker login.
We will need to type our Docker hub account credentials. After, we are logged in. then, we can do a docker push followed by the repository name and tag.
Now it is sending the image to Docker hub.
So, the image has been pushed. Now, let’s go back to our Docker hub account and refresh the page.
We can see the new image appears under my account.
Now, we can click the image and check the image details such as image tags.
Thank you. I hope you have enjoyed it.