One of the most frequently asked question by developers is, how to set up a container registry for storing the Docker images?
A local container registry is useful especially when you do not want to push your local code to public container registries such as Docker-Hub or GCR.
In this article, I am going to explain how to create a local container registry on your own machine. This registry can be accessed from your local system as well as from other servers in the same private network (Provided the hosts’ name etc. is configured properly on the requesting servers).
To begin with, please understand that for this exercise, the registry itself is running as a container and listening at port 5000 of the host. A “Registry” application has been created, we will use the same.
We will launch the registry along with a bind mount, so that data does not go away when the registry is removed.
Docker needs to be installed on your server and its service needs to be running.
For example, for a centos-based system, first run:
$ sudo su
$ yum install docker -y
$ service docker start
The daemon needs to be explicitly set up to use HTTP for the insecure registry.
$ sudo vi /etc/docker/docker
# add this line
DOCKER_OPTS="--insecure-registry localhost:5000"
Close and save the file, then restart the daemon.
$ sudo service docker restart
Run the local registry:
Before we launch the registry containers, we need to arrange for persisting container data on host. This is because the containers are ephemeral, we should persist the content of the registry on host file system. To do that we will use a “bind mount”. The content of the registry will be persisted on ‘pwd’/registry-data.
In this example, the new container will use a host-mounted directory for bin-mount. When the registry server in the container writes image layer data, it appears to be writing to a local directory in the container, but it will be writing to a directory on the host.
Create a directory on the host machine for storing registry data
$ mkdir registry-data
We launch a local container of name “registry”, with “registry:2” image present on public remote registry(dockerhub.com).
$ sudo docker run -d -p 5000:5000 \
--name registry \
-v `pwd`/registry-data:/var/lib/registry \
registry:2
Pull a container image from dockerhub.com
$ sudo docker pull hello-world
Push the image in the local registry
These commands pull a public image from its store, tag it for use in the private registry with the full name localhost:5000/hello-world, and then push it to the local private registry:
$ sudo docker tag hello-world localhost:5000/hello-world
$ sudo docker push localhost:5000/hello-world
Test if the registry is working fine
On the local machine, you can remove the new image tag and the original image, and pull it again from the local registry to verify it was correctly stored:
$ sudo docker rmi localhost:5000/hello-world
$ sudo docker rmi hello-world
$ sudo docker pull localhost:5000/hello-world
Check the content of registry-data on the host
$ tree registry-data
You can try accessing this registry from other systems in your network by properly adding this server’s name to the requester’s /etc/hosts directly. When pushing or pulling the image from this registry you need to give full URL of the server, e.g. <servername>:5000/hello-world:latest
Keywords : containers microservices docker
Understanding blockchain can be a tricky business. Notwithstanding their specialized capacities, blockchains have within them philosophical, social, and ideological underpinnings that must likewise be comprehended. Like people today are connected to the int...
When someone begins learning Kubernetes, the first challenge is to setup the kubernetes cluster. Most of the online tutorials take help of virtual boxes and minikubes, which are good to begin with but have a lot of limitations. This article will guide you t...
Once a microservice is deployed in a container it shall be scheduled, scaled and managed independently. But when you are talking about hundreds of microservices doing that manually would be inefficient. Welcome Kubernetes, for doing container orchestration ...
Containerization/Dockerization is a way of packaging your application and run it in an isolated manner so that it does not matter in which environment it is being deployed. In the DevOps ecosystem containers are being used at large scale. and this is just...