CentOS 8
Sponsored Link

Docker : Use Registry2020/12/14

 
Install Docker-Registry to build Private Registry for Docker images.
[1] Pull the Registry image and run it.
Container Images are located under [/var/lib/regstry] on Registry v2 Container,
so map to mount [/var/lib/docker/registry] on parent Host for Registry Container to use as Persistent Storage.
[root@dlp ~]#
docker pull registry:2

[root@dlp ~]#
mkdir /var/lib/docker/registry

[root@dlp ~]#
docker run -d -p 5000:5000 \
-v /var/lib/docker/registry:/var/lib/registry \
registry:2
266b2df53f6e27db72529d7d832062a6d1e4ff132648f4a28d8a85675ca863f2

[root@dlp ~]#
docker ps

CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                    NAMES
266b2df53f6e   registry:2   "/entrypoint.sh /etc…"   9 seconds ago   Up 9 seconds   0.0.0.0:5000->5000/tcp   thirsty_montalcini


# to use the Registry from other Docker Client Hosts, set like follows

[root@client ~]#
vi /etc/docker/daemon.json
# create new or add

# add Hosts you allow HTTP connection (default is HTTPS)

{
  "insecure-registries":
    [
      "docker.internal:5000",
      "dlp.srv.world:5000"
    ]
}

[root@client ~]#
systemctl restart docker
[root@client ~]#
docker tag nginx dlp.srv.world:5000/nginx:my-registry

[root@client ~]#
docker push dlp.srv.world:5000/nginx:my-registry

[root@client ~]#
docker images

REPOSITORY                 TAG           IMAGE ID       CREATED       SIZE
dlp.srv.world:5000/nginx   my-registry   bc9a0695f571   2 weeks ago   133MB
nginx                      latest        bc9a0695f571   2 weeks ago   133MB
[2] This is for the case you set self-signed certificate and enable HTTPS connection.
This example is based on that certificate were created under the [/etc/pki/tls/certs] directory.
[root@dlp ~]#
docker run -d -p 5000:5000 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/server.key \
-v /etc/pki/tls/certs:/certs \
-v /var/lib/docker/registry:/var/lib/registry \
registry:2
845d961d2abdebef032a8281e9b12710951c01a74900f67f656b80b10107fbfd


# to use the Registry from other Docker Client Hosts, set like follows

# it's not need to add [insecure-registries] but

# need to locate server's certificate on the client side like follows

[root@client ~]#
mkdir -p /etc/docker/certs.d/dlp.srv.world:5000

[root@client ~]#
scp dlp.srv.world:/etc/pki/tls/certs/server.crt /etc/docker/certs.d/dlp.srv.world:5000/ca.crt
[root@client ~]#
docker tag centos dlp.srv.world:5000/centos:my-registry

[root@client ~]#
docker push dlp.srv.world:5000/centos:my-registry

[root@client ~]#
docker images

REPOSITORY                 TAG           IMAGE ID       CREATED       SIZE
dlp.srv.world:5000/nginx   my-registry   bc9a0695f571   2 weeks ago   133MB
nginx                      latest        bc9a0695f571   2 weeks ago   133MB
[3] This is for the case you set valid certificate like Let's Encrypt and enable HTTPS connection.
This example is based on that certificate were created under the [/etc/letsencrypt] directory.
[root@dlp ~]#
docker run -d -p 5000:5000 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/fullchain.pem \
-e REGISTRY_HTTP_TLS_KEY=/certs/privkey.pem \
-v /etc/letsencrypt/live/dlp.srv.world:/certs \
-v /var/lib/docker/registry:/var/lib/registry \
registry:2
28512a4b96d93172b7af66f6b7263fdbff8d729a76659c8b955c60800b557f4f


# to use the Registry from other Docker Client Hosts, set like follows

# it's not need to change any specific settings, it can use with default

[root@client ~]#
docker tag nginx dlp.srv.world:5000/my-nginx:my-registry

[root@client ~]#
docker push dlp.srv.world:5000/my-nginx:my-registry

[root@client ~]#
docker images

dlp.srv.world:5000/my-nginx      my-registry   bc9a0695f571   2 weeks ago   133MB
nginx                            latest        bc9a0695f571   2 weeks ago   133MB
Matched Content