Fedora 29
Sponsored Link

Docker : Use Docker-Registry
2018/11/07
 
Install Docker-Registry to build Private Registry for Docker images.
[1]
This example is based on the environment that SELnux is Permissive or Disabled.
[2]
On The Host which Docker-Registry Container runs, Get SSL Certificates, refer to here.
This example is based on the case that SSL certificates are gotten under the [/etc/letsencrypt/live/dlp.srv.world] and set the [Common Name] as [dlp.srv.world].
[3] Copy to locate Certificates and pull Registry Image (v2). 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 ~]#
mkdir /etc/docker/certs.d/dlp.srv.world:5000

[root@dlp ~]#
cp -p /etc/letsencrypt/live/dlp.srv.world/cert.pem /etc/docker/certs.d/dlp.srv.world:5000/ca.crt
[root@dlp ~]#
docker pull registry:2

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

[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
[root@dlp ~]#
docker ps

CONTAINER ID  IMAGE       COMMAND                  CREATED        STATUS        PORTS                    NAMES
89e65feaa9a6  registry:2  "/entrypoint.sh /e..."   6 seconds ago  Up 4 seconds  0.0.0.0:5000->5000/tcp   musing_lewin
[4] If Firewalld is running, allow mapped port.
[root@dlp ~]#
firewall-cmd --add-port=5000/tcp --permanent

success
[root@dlp ~]#
firewall-cmd --reload

success
[5] For pushing local Image to Registry Container server, set like follows.
# list images on Registry container

[root@dlp ~]#
curl https://dlp.srv.world:5000/v2/_catalog

{"repositories":[]}
[root@dlp ~]#
docker images

REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry       2                   2e2f252f3c88        7 weeks ago         33.3 MB
docker.io/fedora         latest              c582c1438f27        8 weeks ago         254 MB

# set a tag and push

[root@dlp ~]#
docker tag fedora dlp.srv.world:5000/fedora_reg

[root@dlp ~]#
docker push dlp.srv.world:5000/fedora_reg

The push refers to a repository [dlp.srv.world:5000/fedora_reg]
108b1c56d076: Pushed
latest: digest: sha256:6fb84ba634fe68572a2ac99741062695db24b921d0aa72e61ee669902f88c187 size: 529
[root@dlp ~]#
docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZEdocker.io/registry              2                   2e2f252f3c88        7 weeks ago         33.3 MB
dlp.srv.world:5000/fedora_reg   latest              c582c1438f27        8 weeks ago         254 MB
docker.io/fedora                latest              c582c1438f27        8 weeks ago         254 MB

[root@dlp ~]#
curl https://dlp.srv.world:5000/v2/_catalog

{"repositories":["fedora_reg"]}
[6] For getting images from Registry Container server on a Docker node, set like follows.
# get certificates from Registry Container

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

[root@node01 ~]#
cd /etc/docker/certs.d/dlp.srv.world:5000

[root@node01 dlp.srv.world:5000]#
scp dlp.srv.world:"/etc/docker/certs.d/dlp.srv.world:5000/ca.crt" ./
[root@node01 ~]#
docker pull dlp.srv.world:5000/fedora_reg

Using default tag: latest
Trying to pull repository dlp.srv.world:5000/fedora_reg ...
sha256:6fb84ba634fe68572a2ac99741062695db24b921d0aa72e61ee669902f88c187: Pulling from dlp.srv.world:5000/fedora_reg
565884f490d9: Pull complete
Digest: sha256:6fb84ba634fe68572a2ac99741062695db24b921d0aa72e61ee669902f88c187
Status: Downloaded newer image for dlp.srv.world:5000/fedora_reg:latest
[root@node01 ~]#
docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
dlp.srv.world:5000/fedora_reg   latest              c582c1438f27        8 weeks ago         254 MB
Matched Content
 
Tweet