Fedora 27
Sponsored Link

Docker : Use Docker-Registry
2017/12/21
 
Install Docker-Registry to build Private Registry for Docker images.
This example is based on the case to use self-signed certificates.
[1]
This example is based on the environment that SELnux is Permissive or Disabled.
[2]
On The Host which Docker-Registry Container runs, Create SSL Certificates, refer to here.
This example is based on the case that SSL certificates are made under the [/etc/pki/tls/certs] 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/pki/tls/certs/server.crt /etc/pki/tls/certs/domain.crt

[root@dlp ~]#
cp -p /etc/pki/tls/certs/server.key /etc/pki/tls/certs/domain.key

[root@dlp ~]#
cp -p /etc/pki/tls/certs/server.crt /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/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
-v /etc/pki/tls/certs:/certs \
-v /var/lib/docker/registry:/var/lib/registry \
registry:2
[root@dlp ~]#
docker ps

CONTAINER ID IMAGE      COMMAND           CREATED        STATUS        PORTS                    NAMES
94db6d6af717 registry:2 "/entrypoie..."   5 seconds ago  Up 4 seconds  0.0.0.0:5000->5000/tcp   ferve...
[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 -k https://localhost:5000/v2/_catalog

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

REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
srv.world/fedora_httpd   latest              32918df26202        34 minutes ago      564 MB
docker.io/registry       2                   177391bcf802        2 weeks ago         33.3 MB
docker.io/fedora         latest              422dc563ca32        5 weeks ago         252 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]
d32459d9ce23: Pushed
latest: digest: sha256:1b9bfb4e634dc1e5c19d0fa1eb2e5a28a5c2b498e3d3e4ac742bd7f5dae08611 size: 529
[root@dlp ~]#
docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
srv.world/fedora_httpd          latest              32918df26202        39 minutes ago      564 MB
docker.io/registry              2                   177391bcf802        2 weeks ago         33.3 MB
dlp.srv.world:5000/fedora_reg   latest              422dc563ca32        5 weeks ago         252 MB
docker.io/fedora                latest              422dc563ca32        5 weeks ago         252 MB

[root@dlp ~]#
curl -k https://localhost: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:1b9bfb4e634dc1e5c19d0fa1eb2e5a28a5c2b498e3d3e4ac742bd7f5dae08611: Pulling from dlp.srv.world:5000/fedora_reg
a8ee583972c2: Pull complete
Digest: sha256:1b9bfb4e634dc1e5c19d0fa1eb2e5a28a5c2b498e3d3e4ac742bd7f5dae08611
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              422dc563ca32        5 weeks ago         252 MB
Matched Content
 
Tweet