Cara Setup Internal Docker Registry di CentOS 7

ketika kita menginstall docker pada CentOS atau Ubuntu, secara default Docker public registry sudah enable (aktif), sehingga ketika melakukan proses ‘docker pull’ atau ‘docker search’, perintah ini akan langsung mengarah ke docker public registry (Docker Hub).

dalam artikel ini kita membutuhkan 3 mesin, yaitu:

  • docker-registry.routecloud.id (192.168.122.10) => docker internal registry
  • docker-engine1.routecloud.id (192.168.122.11) => server docker untuk admin dan developer  untuk membuat container image dan di push ke internal registry
  • docker-engine2.routecloud.id (192.168.122.12) => server docker untuk download image container (docker pull) untuk menjalankan aplikasi

setting pada /etc/hosts

192.168.122.10 docker-registry.routecloud.id
192.168.122.11 docker-engine1.routecloud.id
192.168.122.12 docker-engine2.routecloud.id

install docker pada semua mesin

yum -y install net-tools vim vim-enhanced vim-common wget git net-tools bind-utils iptables-services bridge-utils bash-completion
curl -fsSL https://get.docker.com/ | sh
systemctl is-active docker ; systemctl enable docker ; systemctl restart docker 

Setup Internal Docker Registry pada meisn docker-registry.routecloud.id

untuk membuat docker registry cukup sederhana, kita cukup download image registry dari docker hub, kemudian dijalankan dengan membuka port 5000

docker pull registry

cek docker history dan ketersediaan image di mesin kita

[root@docker-registry ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
registry            latest              b2b03e9146e1        2 weeks ago         33.3MB
[root@docker-registry ~]# docker history registry
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
b2b03e9146e1        2 weeks ago         /bin/sh -c #(nop)  CMD ["/etc/docker/registr…   0B                  
<missing>           2 weeks ago         /bin/sh -c #(nop)  ENTRYPOINT ["/entrypoint.…   0B                  
<missing>           2 weeks ago         /bin/sh -c #(nop) COPY file:7b57f7ab1a8cf85c…   155B                
<missing>           2 weeks ago         /bin/sh -c #(nop)  EXPOSE 5000/tcp              0B                  
<missing>           2 weeks ago         /bin/sh -c #(nop)  VOLUME [/var/lib/registry]   0B                  
<missing>           2 weeks ago         /bin/sh -c #(nop) COPY file:6c4758d509045dc4…   295B                
<missing>           2 weeks ago         /bin/sh -c #(nop) COPY file:b99d4fe47ad1addf…   22.8MB              
<missing>           2 weeks ago         /bin/sh -c set -ex     && apk add --no-cache…   5.71MB              
<missing>           2 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
<missing>           2 weeks ago         /bin/sh -c #(nop) ADD file:3861bd6a79d134647…   4.82MB

sebelumnya buat directory /mnt/registry , sebagai volume container registry

mkdir /mnt/registry

jalankan container registry seperti dibawah ini

 docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v /mnt/registry:/var/lib/registry \
  registry

pastikan container registry runing

[root@docker-registry ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
e5850a574233        registry            "/entrypoint.sh /etc…"   14 minutes ago      Up 14 minutes       0.0.0.0:5000->5000/tcp   registry

Buat dan Push image ke internal docker registry, untuk proses push image ke docker registry kita jalankan pada mesin docker-engine1

 docker pull ubuntu

cek kembali ketersediaan image

[root@docker-engine1 ~]# docker images
REPOSITORY                                  TAG                 IMAGE ID            CREATED             SIZE
ubuntu                                      latest              74f8760a2a8b        7 days ago          82.4MB

setelah itu harus di tambahkan tag pada image yang akan di push

docker tag ubuntu docker-registry.routecloud.id:5000/ubuntu
REPOSITORY                                  TAG                 IMAGE ID            CREATED             SIZE
docker-registry.routecloud.id:5000/ubuntu   latest              74f8760a2a8b        7 days ago          82.4MB
ubuntu                                      latest              74f8760a2a8b        7 days ago          82.4MB

pada docker image tersebut memiliki image ID yang sama.

sebelum push (upload) image ke docker registry, harus setting insecure-registry karena secara default akan membolehkan protokol https saja

[root@docker-engine1 ~]# vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd --insecure-registry 192.168.122.0/24

reload daemon dan restart docker

[root@docker-engine1 ~]#  systemctl daemon-reload; systemctl restart docker

setelah itu docker push ke internal registry

[root@docker-engine1 ~]# docker push docker-registry.routecloud.id:5000/ubuntu
The push refers to repository [docker-registry.routecloud.id:5000/ubuntu]
374f3534200b: Pushed 
8fec0692e6a1: Pushed 
219d5a9f3bbe: Pushed 
67b9b2a215ea: Pushed 
956940650d5d: Pushed 
latest: digest: sha256:b89c04130e5f10e0958d16e6c17969d11b529072697d967be9045184d7da5258 size: 1357

untuk memastikan image terupload pada internal registry pada mesin docker-registry.routecloud.id, bisa dicek pada directory

[root@docker-registry ~]# ls /mnt/registry/docker/registry/v2/repositories/
ubuntu

setelah itu, docker pull untuk mendownload image dari internal docker registry dari mesin docker-engine2, secara default akan mengdownload mengunakan https, maka dari itu harus diset insecure-registry

[root@docker-engine1 ~]# vim /usr/lib/systemd/system/docker.service 
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.122.0/24

reload daemon dan restart docker

[root@docker-engine1 ~]#  systemctl daemon-reload; systemctl restart docker

kemudian docker pull image ke internal registry

[root@docker-engine2 ~]# docker pull docker-registry.routecloud.id:5000/ubuntu
Using default tag: latest
latest: Pulling from ubuntu
7996ebd2246a: Pull complete 
de532f9a4f9f: Pull complete 
7de2709b2a83: Pull complete 
70b6ac64a142: Pull complete 
23caf550e032: Pull complete 
Digest: sha256:b89c04130e5f10e0958d16e6c17969d11b529072697d967be9045184d7da5258
Status: Downloaded newer image for docker-registry.routecloud.id:5000/ubuntu:latest

cek ketersediaan image

[root@docker-engine2 ~]# docker images
REPOSITORY                                  TAG                 IMAGE ID            CREATED             SIZE
docker-registry.routecloud.id:5000/ubuntu   latest              74f8760a2a8b        7 days ago          82.4MB

cukup sekian tutorial setup internal docker registry, semoga bermanfaat

wassalamualaikum

 

About the author
Alan Adi Prastyo

Routecloud Networks

Information about Server, Linux and Computer Network.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Routecloud Networks.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.