Ubuntu 18.04
Sponsored Link

Docker : Use Docker-Registry2018/06/12

 
Install Docker-Registry to build Private Registry for Docker images.
[1]
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].
[2] 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 -p /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
33eeb464bf7786d26e8692f28085e638b2a348233f67dc8cc2901853a039683d
root@dlp:~#
docker ps

CONTAINER ID  IMAGE       COMMAND                  CREATED          STATUS         PORTS                    NAMES
33eeb464bf77  registry:2  "/entrypoint.sh /etc…"   18 seconds ago   Up 18 seconds  0.0.0.0:5000->5000/tcp   competent_bhabha
[3] 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
storage                    latest              f250059f0ff5        16 minutes ago      1.15MB
web_server                 latest              46fdaf40a0fe        23 minutes ago      313MB
srv.world/ubuntu_apache2   latest              b2d00f9d9fb4        About an hour ago   218MB
ubuntu                     latest              113a43faa138        6 days ago          81.2MB
busybox                    latest              8c811b4aec35        2 weeks ago         1.15MB
registry                   2                   d1fd7d86a825        5 months ago        33.3MB

# set a tag and push

root@dlp:~#
docker tag ubuntu dlp.srv.world:5000/ubuntu_reg

root@dlp:~#
docker push dlp.srv.world:5000/ubuntu_reg

The push refers to repository [dlp.srv.world:5000/ubuntu_reg]
.....
.....
db9476e6d963: Pushed
latest: digest: sha256:e7def0d56013d50204d73bb588d99e0baa7d69ea1bc1157549b898eb67287612 size: 1357
root@dlp:~#
docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
storage                         latest              f250059f0ff5        17 minutes ago      1.15MB
web_server                      latest              46fdaf40a0fe        24 minutes ago      313MB
srv.world/ubuntu_apache2        latest              b2d00f9d9fb4        About an hour ago   218MB
ubuntu                          latest              113a43faa138        6 days ago          81.2MB
dlp.srv.world:5000/ubuntu_reg   latest              113a43faa138        6 days ago          81.2MB
busybox                         latest              8c811b4aec35        2 weeks ago         1.15MB
registry                        2                   d1fd7d86a825        5 months ago        33.3MB

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

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

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

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

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

Using default tag: latest
latest: Pulling from ubuntu_reg
6b98dfc16071: Pull complete
4001a1209541: Pull complete
6319fc68c576: Pull complete
b24603670dc3: Pull complete
97f170c87c6f: Pull complete
Digest: sha256:e7def0d56013d50204d73bb588d99e0baa7d69ea1bc1157549b898eb67287612
Status: Downloaded newer image for dlp.srv.world:5000/ubuntu_reg:latest
root@node01:~#
docker images

REPOSITORY                      TAG         IMAGE ID            CREATED             SIZE
dlp.srv.world:5000/ubuntu_reg   latest      113a43faa138        6 days ago          81.2MB
Matched Content