Setting up your own private Docker registry

In this article, we are going to set up our private Docker registry in CentOS7 VM.

We are going to use the VM (docker-loc-registry) to set up the private Docker registry.

VM (docker-loc-registry) details:

[root@docker-loc-registry ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@docker-loc-registry ~]#

[root@docker-loc-registry ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.43.48 docker-loc-registry
[root@docker-loc-registry ~]#

First, we will install the docker as below,

[root@docker-loc-registry ~]# yum install docker

Install the Docker Registry and Start & enable the Docker Registry Service

[root@docker-loc-registry ~]# yum install docker-distribution

[root@docker-loc-registry ~]# systemctl start docker-distribution.service
[root@docker-loc-registry ~]# systemctl enable docker-distribution.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker-distribution.service to /usr/lib/systemd/system/docker-distribution.service.
[root@docker-loc-registry ~]#

Docker Registry settings can be found below file,

[root@docker-loc-registry ~]# cat /etc/docker-distribution/registry/config.yml
version: 0.1
log:
fields:
service: registry
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
[root@docker-loc-registry ~]#

Images will be saved in the directory ‘/var/lib/registry’ and service will use the port number :5000

so our docker registry can be accessed by using ‘docker-loc-registry:5000’

We can add our insecure registry to Docker engine by editing the file ‘/etc/docker/daemon.json’ and restart docker service.

[root@docker-loc-registry ~]# cat /etc/docker/daemon.json
{
“insecure-registries” : [“docker-loc-registry:5000”]
}
[root@docker-loc-registry ~]#

[root@docker-loc-registry ~]# systemctl restart docker
[root@docker-loc-registry ~]#

As of now, we do not have any docker images,

[root@docker-loc-registry ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@docker-loc-registry ~]#

We can pull the ‘nginx’ docker image from Docker Hub and push/store it our local registry.

[root@docker-loc-registry ~]# docker pull nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx …
latest: Pulling from docker.io/library/nginx
27833a3ba0a5: Pull complete
ea005e36e544: Pull complete
d172c7f0578d: Pull complete
Digest: sha256:e71b1bf4281f25533cf15e6e5f9be4dac74d2328152edf7ecde23abc54e16c1c
Status: Downloaded newer image for docker.io/nginx:latest
[root@docker-loc-registry ~]#

Listing out docker images:

[root@docker-loc-registry ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest 27a188018e18 2 weeks ago 109 MB
[root@docker-loc-registry ~]#

We are going to give tag to ‘nginx’ image as ‘docker-loc-registry:5000/nginx_lo_reg’

[root@docker-loc-registry ~]# docker tag nginx docker-loc-registry:5000/nginx_lo_reg
[root@docker-loc-registry ~]#

Listing out docker images:

[root@docker-loc-registry ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-loc-registry:5000/nginx_lo_reg latest 27a188018e18 2 weeks ago 109 MB
docker.io/nginx latest 27a188018e18 2 weeks ago 109 MB
[root@docker-loc-registry ~]#

Now push that image to our private registry as below,

[root@docker-loc-registry ~]# docker push docker-loc-registry:5000/nginx_lo_reg
The push refers to a repository [docker-loc-registry:5000/nginx_lo_reg]
fc4c9f8e7dac: Pushed
912ed487215b: Pushed
5dacd731af1b: Pushed
latest: digest: sha256:c10f4146f30fda9f40946bc114afeb1f4e867877c49283207a08ddbcf1778790 size: 948
[root@docker-loc-registry ~]#

we can see that Docker image ‘nginx_lo_reg ‘ is stored under location ‘/var/lib/registry’ as below,

[root@docker-loc-registry ~]# ls -lrt /var/lib/registry/docker/registry/v2/repositories
total 0
drwxr-xr-x. 5 root root 55 May 4 18:28 nginx_lo_reg
[root@docker-loc-registry ~]#

We can remove the images which we have pulled from Docker Hub,

[root@docker-loc-registry ~]# docker image remove docker-loc-registry:5000/nginx_lo_reg docker.io/nginx
Untagged: docker-loc-registry:5000/nginx_lo_reg:latest
Untagged: docker-loc-registry:5000/nginx_lo_reg@sha256:c10f4146f30fda9f40946bc114afeb1f4e867877c49283207a08ddbcf1778790
Untagged: docker.io/nginx:latest
Untagged: docker.io/nginx@sha256:e71b1bf4281f25533cf15e6e5f9be4dac74d2328152edf7ecde23abc54e16c1c
Deleted: sha256:27a188018e1847b312022b02146bb7ac3da54e96fab838b7db9f102c8c3dd778
Deleted: sha256:261d1996088c57b71d8ea9412f719bcbb8f4cb68a6e463d30abb85cc5fc5724b
Deleted: sha256:e6fbd1f039a7391ab57afeb1b11a73781bcbd6ae8041d98c5988b90c46ce5726
Deleted: sha256:5dacd731af1b0386ead06c8b1feff9f65d9e0bdfec032d2cd0bc03690698feda
[root@docker-loc-registry ~]#

No image is available as below,

[root@docker-loc-registry ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@docker-loc-registry ~]#

Now we can pull the images from our private registry as below,

[root@docker-loc-registry ~]# docker pull docker-loc-registry:5000/nginx_lo_reg
Using default tag: latest
Trying to pull repository docker-loc-registry:5000/nginx_lo_reg …
latest: Pulling from docker-loc-registry:5000/nginx_lo_reg
27833a3ba0a5: Pull complete
ea005e36e544: Pull complete
d172c7f0578d: Pull complete
Digest: sha256:c10f4146f30fda9f40946bc114afeb1f4e867877c49283207a08ddbcf1778790
Status: Downloaded newer image for docker-loc-registry:5000/nginx_lo_reg:latest
[root@docker-loc-registry ~]#

List out the available docker images,

[root@docker-loc-registry ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-loc-registry:5000/nginx_lo_reg latest 27a188018e18 2 weeks ago 109 MB
[root@docker-loc-registry ~]#

Hence, we have set up our simple private Docker registry and we did docker images push and pull.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: