Docker registries are a necessary part of the Docker platform that plays a vital role in publishing and managing Docker images. The Docker registries are mainly categorized into two types: Official registry (Docker Hub) and private registry that users specify for personal use. Users can share and publish their Docker images on these registries.
This blog will explain how to push a Docker image to a private registry using Docker “push” command.
How to Use “docker push” to Push Image to Private Registry?
The “docker push” command is a command line utility used to push or publish Docker images on Docker’s private or official registry. To use this command to push the image to the private registry, utilize the given procedure.
Step 1: Pull Docker Image From Docker Official Registry
First, pull any image from the Docker official registry “Docker Hub”. For instance, we have pulled the “alpine” image:
Step 2: Log in to Private Registry
Next, log in to your private registry with the help of the “docker login” command. For instance, we have logged in to our Docker registry operating on “localhost:5000”:
Note: Users must start the registry container before logging in to Docker private registry.
Step 3: Create Target Image
Next, create a target image from the newly pulled image that will then be pushed to the private registry. To create a target image, utilize the “docker tag <source-image> <registry-source>/<target-image>” command:
To verify if the image is created or not, check out the images list using the “docker images” command:
Step 4: Push Docker Image to Private Registry
Push the image to the Docker private registry using the “docker push <target-image>” command:
Verify if the image is pushed or not by visiting the private registry catalogs. For instance, we have visited the “localhost:5000/v2/_catalog” URL on the browser:
The above output shows that we have successfully pushed the Docker image to the private registry.
Conclusion
The “docker push” command is used to push Docker images to the registry either in the private registry or on the Docker Hub registry. In order to push an image to the private registry, first, start the registry container and log in to the private registry. Then, create a target image and push it to Docker private registry using the “docker push <source-registry/<image-name>” command. This write-up has demonstrated how to push the image to a private registry.