Featured Video Play Icon

How To Setup a Private Docker Registry

Docker Hub is a powerful platform that allows developers to easily create and manage their own private registries. A private registry is a great way to keep your Docker images safe and secure, while still allowing others to access and use them. In this article, we’ll walk you through the process of how to setup a private Docker registry on Docker Hub.

Lead Developer Career Guide Banner 02

What is a Docker Image?

Docker images are the building blocks of containerized applications. They are pre-configured snapshots of an application and its dependencies, including the operating system, runtime, libraries, and other components. With Docker Hub, you can easily share and distribute these images to other developers, teams, or even entire organizations.

How To Pull An Image From Docker Hub

To pull an image from Docker Hub, you can use the docker pull command. This command takes the name of the image and the tag (the version of the image) as arguments. For example, to pull the latest version of the public community static-site image from Docker Hub, the command would be:

docker pull prakhar1989/static-site

After pulling image from the hub, you can use docker run command to start a container from the pulled image. In this instance, we are using the “d” flag to run the container in detached mode and the “p” flag which will publish the container’s port to the host.

docker run -d -P --name static-site prakhar1989/static-site

How To Setup a Private Docker Registry in Docker Hub

First, you’ll need to create a new account on Docker Hub if you don’t already have one. Once you’re logged in, navigate to the “Repositories” section and click the “Create Repository” button. Here, you’ll be prompted to enter a name for your new registry, as well as a description.

Next, you’ll need to configure your new registry’s settings. In the “Visibility” section, you can choose who has access to your registry by setting it to either “Public” or “Private”. If you choose “Private”, you can invite specific users to access your registry by entering their Docker Hub username.

how to setup a private docker registry in Docker hub
Setup a Private Docker Registry in Docker Hub

Once you have setup a private docker registry, you can log into it using the command docker login. You will be prompted to enter your username and password for Docker Hub.

docker login

How To Push An Image To a Docker Hub Registry

Once your registry is set up, you can start pushing images to it. First, you should tag your local image using the name of your new repository to keep things organized using the docker tag command. Then, you can use the docker push command, followed by the name of your registry and the name of the image you want to push. For example, my registry is named “sbenhoff/demo” and I’m pushing an image named “static-site”, so I would use the command docker push sbenhoff/demo:static-site.

docker tag prakhar1989/static-site sbenhoff/demo:static-site
docker push sbenhoff/demo:static-site

You can also view your registry using the Docker extension for VSCode and logging into your Docker Hub registry in the Registries panel.

how to setup a private docker registry and view it using the VSCode extension for Docker.
View Docker Hub Registry Using the Docker Extension for VSCode

How To Pull An Image From a Docker Hub Registry

You can also pull images from your private registry by using the docker pull command, followed by the name of your registry and the name of the image you want to pull. In this example, I’m pulling the same image that we just pushed so it should tell me that it’s already up to date.

docker pull sbenhoff/demo:static-site

Setting up a private Docker registry on Docker Hub is a simple and straightforward process. By creating a private registry, you can ensure that your images are safe and secure, while still allowing others to access and use them. With the right setup, you can easily push and pull images to and from your registry, making your development process more efficient.

Tactics and Tools for Troubleshooting Docker – Online Course Available on Pluralsight

Tactics and Tools for Troubleshooting Docker on Pluralsight
Tactics and Tools for Troubleshooting Docker – Online Course Available on Pluralsight

If you’re struggling with Docker errors, check out my Pluralsight course, Tactics and Tools for Troubleshooting Docker. This course provides developers with the skills they need to troubleshoot and fix the most common Docker errors. By the end of this course, you will have the skills you need to reduce the time it takes you to assess and fix issues. Click the link below to get started with a free trial today!