Of course, you could use DockerHub, but that’s placing your trust in a third party.
A private Docker registry allows you to store and index your Docker images on your local machine, or any machine you plan to use for container development, so you can work with those images without having to worry that your information and your code is unsafe. Having your own private registry is also quite convenient.
How do you deploy such a thing? Let me show you.
Note: This isn’t a LAN-based registry, so you won’t be able to access it from any machine other than the one hosting the registry–this is for security purposes. You can deploy this on your desktop, laptop, a server on your LAN or even your cloud-based host on AWS, Google Cloud, Rackspace, Microsoft Azure or Linode. As long as the hosting machine supports Docker, you’re good to go.
Just remember, the push and pull of images to and from this registry is restricted to the hosting machine.
SEE: Power checklist: Local email server-to-cloud migration (TechRepublic Premium)
What you’ll need
To make this work, you’ll need an operating system that supports Docker. I’m going to demonstrate on Ubuntu Server 20.04, but it should work on most operating systems.
How to install Docker
The first thing we’ll do is install Docker. To do that, log in to your server and issue the command:
sudo apt-get install docker.io
Once the installation completes, add your user to the docker group with the command:
sudo usermod -aG docker $USER
Log out and log back in, so the changes will take effect.
How to deploy the registry
The local registry can be deployed with the command:
docker run -d -p 5000:5000 --name registry --restart=always registry:latest
The above command will pull down the official registry container and deploy it on port 5000. When it completes, you’re ready to start working with your local registry.
How to push images to your registry
You can now start pushing images to your local registry. To do that, you must first tag an image like so:
docker tag IMAGE localhost:5000/IMAGE
Where IMAGE is the name of the image to be tagged. You could also use the IP address of the hosting machine (instead of localhost). For instance, say you’ve pulled down the latest Ubuntu image and plan on working with it. You could tag it like so:
docker image tag ubuntu:latest localhost:5000/ubuntu:latest
With the image tagged, you can then push it to your local registry with the command:
docker push localhost:5000/ubuntu:latest
To pull that same image from your registry, the command would be:
docker pull localhost:5000/ubuntu:latest
To view a list of all your available images, issue the command:
curl -X GET http://localhost:5000/v2/_catalog
You should see your images listed as such:
Keep adding images and the output of the curl command would look like:
And that’s all there is to deploy your own personal Docker registry. Remember: This setup is intended to only be used on the machine you’ll be developing on, so this is not a LAN-based Docker registry. For those cloud-native developers who simply want a quick and easy registry to use on the same machine they’ll be developing on, this is just the ticket.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.