์ด๋ฒ ํฌ์คํ
์์๋ 2๊ฐ์ ํธ์คํธ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
ํ๋๋ Master Node๋ก Registry ์๋ฒ ์ญํ ์ ํ ๋
ธ๋ํ๊ณ , ํ๋๋ Worker Node๋ก Registry์ ์ด๋ฏธ์ง๋ฅผ Pull/Push ํ ๋
ธ๋์
๋๋ค
์ ๋ AWS EC2๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌ์ฑํ์์ต๋๋ค :)
1. Docker Registry ์ค์ ํ๊ธฐ
1-1) Master Node ํ์ธ
๋๊ฐ์ ํธ์คํธ ์ค ๋จผ์ Mager ๋
ธ๋์ ์ค์ ์ ํ์ธํด๋ด
๋๋ค :)
๋จผ์ , Hostname์ ํ์ธํฉ๋๋ค. (ํธ์คํธ ์ด๋ฆ ๋ณ๊ฒฝ์ #hostnamectl set-hostname <๋ณ๊ฒฝํ ์ด๋ฆ> ๋ช
๋ น์ด๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅํฉ๋๋ค)
[root@docker-master /]# hostnamectl
Static hostname: docker-master.test.dom
Icon name: computer-vm
Chassis: vm
Machine ID: 3d5c05376530a2eb49e3e90576f83c5b
Boot ID: 6e41fcc8e6b84010806c700415ff349c
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1062.12.1.el7.x86_64
Architecture: x86-64
ํธ์คํธ์ IP๋ฅผ ํ์ธํฉ๋๋ค.
[root@docker-master /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
link/ether 02:86:58:3f:58:7c brd ff:ff:ff:ff:ff:ff
inet 172.31.6.114/20 brd 172.31.15.255 scope global dynamic ens5
valid_lft 2884sec preferred_lft 2884sec
inet6 fe80::86:58ff:fe3f:587c/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:23:65:ae:a6 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
ํธ์คํธ ์ด๋ฆ๊ณผ IP๋ฅผ ์ ์ํ ํ์ผ /etc/hosts ์ ํ์ธํฉ๋๋ค!
[root@docker-master /]# vi /etc/hosts
[root@docker-master /]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.31.6.114 docker-master.test.dom
127.31.3.201 docker-worker.test.dom
ping์ผ๋ก ํธ์คํธ๊ฐ์ ํต์ ์ ํ ์คํธ ํฉ๋๋ค.
[root@docker-master centos]# ping -c3 docker-worker.test.dom
PING docker-worker.test.dom (127.31.3.201) 56(84) bytes of data.
64 bytes from docker-worker.test.dom (127.31.3.201): icmp_seq=1 ttl=64 time=0.028 ms
64 bytes from docker-worker.test.dom (127.31.3.201): icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from docker-worker.test.dom (127.31.3.201): icmp_seq=3 ttl=64 time=0.038 ms
--- docker-worker.test.dom ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.028/0.035/0.040/0.007 ms
1-2) Worker Node ํ์ธ
๋๊ฐ์ ํธ์คํธ ์ค ๋๋ฒ์งธ, Worker ๋
ธ๋์ ์ค์ ์ ํ์ธํด๋ด
๋๋ค :)
๋จผ์ , Hostname์ ํ์ธํฉ๋๋ค. (ํธ์คํธ ์ด๋ฆ ๋ณ๊ฒฝ์ #hostnamectl set-hostname <๋ณ๊ฒฝํ ์ด๋ฆ> ๋ช
๋ น์ด๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅํฉ๋๋ค)
[root@docker-worker /]# hostnamectl
Static hostname: docker-worker.test.dom
Icon name: computer-vm
Chassis: vm
Machine ID: 3d5c05376530a2eb49e3e90576f83c5b
Boot ID: 1a791934c0e447128740450f9e9f731e
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1062.12.1.el7.x86_64
Architecture: x86-64
ํธ์คํธ์ IP๋ฅผ ํ์ธํฉ๋๋ค.
[root@docker-worker /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
link/ether 02:c2:72:d9:ee:7c brd ff:ff:ff:ff:ff:ff
inet 172.31.3.201/20 brd 172.31.15.255 scope global dynamic ens5
valid_lft 2471sec preferred_lft 2471sec
inet6 fe80::c2:72ff:fed9:ee7c/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:6e:fa:50:8e brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:6eff:fefa:508e/64 scope link
valid_lft forever preferred_lft forever
ํธ์คํธ ์ด๋ฆ๊ณผ IP๋ฅผ ์ ์ํ ํ์ผ /etc/hosts ์ ํ์ธํฉ๋๋ค!
[root@docker-worker /]# vi /etc/hosts
[root@docker-worker /]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.31.6.114 docker-master.test.dom
127.31.3.201 docker-worker.test.dom
ping์ผ๋ก ํธ์คํธ๊ฐ์ ํต์ ์ ํ ์คํธ ํฉ๋๋ค.
[root@docker-worker /]# ping -c3 docker-master.test.dom
PING docker-master.test.dom (172.31.6.114) 56(84) bytes of data.
64 bytes from docker-master.test.dom (172.31.6.114): icmp_seq=1 ttl=64 time=0.170 ms
64 bytes from docker-master.test.dom (172.31.6.114): icmp_seq=2 ttl=64 time=0.133 ms
64 bytes from docker-master.test.dom (172.31.6.114): icmp_seq=3 ttl=64 time=0.134 ms
--- docker-master.test.dom ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.133/0.145/0.170/0.022 ms
1-3) Master Node PrivateRegistry ๊ตฌ์ฑํ๊ธฐ
์ด๋ฒ์๋ Master ํธ์คํธ์์ Private Registry๋ฅผ ๊ตฌ์ฑํด๋ณด๋ ค๊ณ ํฉ๋๋ค.
registry๋ผ๋ ์ปจํ
์ด๋๋ฅผ ์คํํด๋ด
์๋ค! :)
[root@docker-master /]# docker run -d -p 5000:5000 -v /var/lib/registry:/var/lib/registry --restart=always --name registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
cbdbe7a5bc2a: Pull complete
47112e65547d: Pull complete
46bcb632e506: Pull complete
c1cc712bcecd: Pull complete
3db6272dcbfa: Pull complete
Digest: sha256:8be26f81ffea54106bae012c6f349df70f4d5e7e2ec01b143c46e2c03b9e551d
Status: Downloaded newer image for registry:2
d941526862ea2e603743a83b0a80228a64ed5797af75446c5af3598b2e554b38
์ปจํ ์ด๋ ๋ชฉ๋ก์ ํ์ธํด๋ณด๋, Registry์ปจํ ์ด๋๊ฐ ์ ์ด์์ค์ด๋ค์.
[root@docker-master /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d941526862ea registry:2 "/entrypoint.sh /etc…" 8 seconds ago Up 7 seconds 0.0.0.0:5000->5000/tcp registry
1-4) Worker Node Private Regisrty ์ฌ์ฉํ๊ธฐ
๋์ปค ๋ฐ๋ชฌ์ ์กฐ๊ธ ์์ ํ ์์ ์ ๋๋ค. :)
๊ธฐ๋ณธ์ ์ผ๋ก docker ๋ช
๋ น์ด๋ก ์ด๋ฏธ์ง๋ฅผ Pull ํ ๋๋ ๋ชจ๋ https ํต์ ์
๋๋ค.
๊ทธ๋ฐ๋ฐ, ์ ํฌ๊ฐ ์์์ ๋ง๋ Master ํธ์คํธ์ Registry๋ SSL ์ค์ ์ด ์๋์ด์์ด์.. httpํต์ ๋ง ๊ฐ๋ฅํฉ๋๋ค.
๋ง์ฝ ์๋์ ์ค์ ์ ํ์ง ์๊ณ , Master ํธ์คํธ์ ์ค์ ๋ Private Repository๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๋ค๋ฉด, ์ค๋ฅ๋ฅผ ๋ง๋๊ฒ ๋ฉ๋๋ค :)
์ฆ, http ํต์ ์ด ๊ฐ๋ฅํ๋๋ก ์๋ insecure ์ค์ ์ ํด์ค์ผํฉ๋๋ค.
์, /etc/docker/daemon.json ์ ์์ ํฉ๋๋ค!
[root@docker-worker /]# cat /etc/docker/daemon.json
{
"insecure-registries": ["docker-master.test.dom:5000"]
}
์ ๋ฐ๋ชฌ ์ค์ ์ด ๋ฐ์ ๋ ์์๋๋ก docker ๋ฐ๋ชฌ์ ์ฌ์์ ํฉ๋๋ค.
[root@docker-worker /]# systemctl restart docker
๋ฐ๋ชฌ์ ์ด์์ด ์๋์ง, Status๋ฅผ ํ์ธํด๋ด ์๋ค :)
[root@docker-worker /]# systemctl status docker
โ docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since ํ 2020-09-29 00:56:51 UTC; 3s ago
Docs: https://docs.docker.com
Main PID: 11589 (dockerd)
Tasks: 10
Memory: 43.4M
CGroup: /system.slice/docker.service
โโ11589 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.690900672Z" level=info msg="ccR...grpc
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.690917992Z" level=info msg="Cli...grpc
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.699194401Z" level=info msg="[gr...ay2"
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.704697067Z" level=info msg="Loa...rt."
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.828753543Z" level=info msg="Def...ess"
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.865544811Z" level=info msg="Loa...ne."
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.882722824Z" level=info msg="Doc...3.13
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.882802675Z" level=info msg="Dae...ion"
9์ 29 00:56:51 docker-worker.test.dom systemd[1]: Started Docker Application Container Engine.
9์ 29 00:56:51 docker-worker.test.dom dockerd[11589]: time="2020-09-29T00:56:51.901919765Z" level=info msg="API...ock"
Hint: Some lines were ellipsized, use -l to show in full.
์ด์ httpd ์ด๋ฏธ์ง๋ฅผ pull (์ด๋ฏธ์ง ๋ค์ด๋ก๋) ํ๊ณ , ํ๊ทธ๋ฅผ ๋ฌ์์ master ๋ ธ๋์ ์๋ Private Registry์ ์ด๋ฏธ์ง๋ฅผ Push ํ๊ฒ ์ต๋๋ค.
[root@docker-worker /]# docker pull httpd:latest
latest: Pulling from library/httpd
d121f8d1c412: Already exists
9cd35c2006cf: Pull complete
b6b9dec6e0f8: Pull complete
fc3f9b55fcc2: Pull complete
802357647f64: Pull complete
Digest: sha256:5ce7c20e45b407607f30b8f8ba435671c2ff80440d12645527be670eb8ce1961
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
์ด๋ฏธ์ง๋ฅผ ํ์ธํด๋ด ์๋ค.
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 417af7dc28bc 13 days ago 138MB
httpd ์ด๋ฏธ์ง์ ํ๊ทธ๋ฅผ ๋ณ๊ฒฝํด๋ด ์๋ค.
docker tag <์ต์ > <์ด๋ฏธ์ง ์ด๋ฆ>:<ํ๊ทธ> <์ ์ฅ์ ์ฃผ์, ์ฌ์ฉ์๋ช >/<์ด๋ฏธ์ง ์ด๋ฆ>:<ํ๊ทธ>
๋ ํฌ์งํ ๋ฆฌ๊ฐ docker-master.test.dom:5000/httpd๋ก ๋ฐ๋์๋ค์!
[root@docker-worker /]# docker tag httpd docker-master.test.dom:5000/httpd
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 417af7dc28bc 13 days ago 138MB
docker-master.test.dom:5000/httpd latest 417af7dc28bc 13 days ago 138MB
Push ๋ช ๋ น์ด๋ก ์ด ์ด๋ฏธ์ง๋ฅผ Master Private Registry๋ก ํธ์ฌ ํฉ๋๋ค.
[root@docker-worker /]# docker push docker-master.test.dom:5000/httpd
The push refers to repository [docker-master.test.dom:5000/httpd]
9f3f3dd7b0c2: Pushed
51eabf53c0c9: Pushed
6ce7826117a0: Pushed
d37da03a9458: Pushed
07cab4339852: Pushed
latest: digest: sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db size: 1366
Registry ํ
์คํธ ์ ์, ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ ๊นจ๋ํ๊ฒ ์ง์์ค์๋ค.
ํท๊ฐ๋ฆฌ์ง ์๊ฒ์ :)
[root@docker-worker /]# docker rmi -f $(docker images -q)
Untagged: docker-master.test.dom:5000/httpd:latest
Untagged: docker-master.test.dom:5000/httpd@sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db
Untagged: httpd:latest
Untagged: httpd@sha256:5ce7c20e45b407607f30b8f8ba435671c2ff80440d12645527be670eb8ce1961
Deleted: sha256:417af7dc28bc66aa2cc4af18cbfa934cc55f46721b101beac68b9f5c33d7fcb2
Deleted: sha256:2929da9174351249481441a39d499183fa7bb416fbfc2dfc36cdcfca001ace81
Deleted: sha256:46fba7aa125a55a717a218e2750c991bbf4d9e7bb66c56bacde76338a5b38f16
Deleted: sha256:a8151056fecd4987dd3fcde6579e8d34b72c1e39dfd5ac63209cffa0b0befb08
Deleted: sha256:97635989e45ed57deef09cd09be52d008a073f2e1e045a1ba91956fbc2db2961
์ด๋ฏธ์ง๊ฐ ์ ๋ถ ์ ์ง์์ก๋ค์.
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
์, ์ด๋ฒ์๋ docker Pull ๋ช
๋ น์ด๋ก httpd ์ด๋ฏธ์ง๋ฅผ ๋ค์ ๋ค์ด๋ก๋ ํฉ์๋ค!
์๊น ์ฒ์๊ณผ ๋ค๋ฅธ์ ์ httpd ์ด๋ฏธ์ง ์์ ํน์ ๋ ํฌ์งํ ๋ฆฌ์์ ๊ฐ์ ธ์ค๋๋ก ์ง์ ํ์ต๋๋ค.
[root@docker-worker /]# docker pull docker-master.test.dom:5000/httpd
Using default tag: latest
latest: Pulling from httpd
d121f8d1c412: Already exists
9cd35c2006cf: Pull complete
b6b9dec6e0f8: Pull complete
fc3f9b55fcc2: Pull complete
802357647f64: Pull complete
Digest: sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db
Status: Downloaded newer image for docker-master.test.dom:5000/httpd:latest
docker-master.test.dom:5000/httpd:latest
๋์ปค ์ด๋ฏธ์ง๋ฅผ ํ์ธํด๋ด ๋๋ค.
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-master.test.dom:5000/httpd latest 417af7dc28bc 13 days ago 138MB
1-5) Master Node ์ค ์ ์ฅ ๊ฒฝ๋ก ํ์ธ & ๋ ์ง์คํธ๋ฆฌ ์ปจํ ์ด๋ ์ญ์
Master ๋
ธ๋ ์ด๋์ ์ด๋ฏธ์ง๋ค์ด ์ ์ฅ๋๋์ง ํ์ธํด๋ด
๋๋ค.
[root@docker-master /]# ls -al /var/lib/registry/docker/registry/v2/repositories/httpd/_layers/sha256/
ํฉ๊ณ 4
drwxr-xr-x. 8 root root 4096 9์ 29 01:08 .
drwxr-xr-x. 3 root root 20 9์ 29 01:08 ..
drwxr-xr-x. 2 root root 18 9์ 29 01:08 417af7dc28bc66aa2cc4af18cbfa934cc55f46721b101beac68b9f5c33d7fcb2
drwxr-xr-x. 2 root root 18 9์ 29 01:08 802357647f642714e7ed35c6c28be6f1e8e3591764bc588f752cec6e13fb304b
drwxr-xr-x. 2 root root 18 9์ 29 01:08 9cd35c2006cf02c3040a3d4b7feed7e0c53d77a8318a97d632929194b0352e67
drwxr-xr-x. 2 root root 18 9์ 29 01:08 b6b9dec6e0f83ec34ba156463e1156deef38009e6f19b663864805527339bd0f
drwxr-xr-x. 2 root root 18 9์ 29 01:08 d121f8d1c4128ebc1e95e5bfad90a0189b84eadbbb2fbaad20cbb26d20b2c8a2
drwxr-xr-x. 2 root root 18 9์ 29 01:08 fc3f9b55fcc21c05be1d8ef3a6cf5a15967138bd8e4511195b8d36b80f9f0f5eโ
์ด์ Registry ์ปจํ ์ด๋๋ฅผ ์ญ์ ํฉ๋๋ค.
[root@docker-master /]# docker rm -f $(docker ps -aq)
b4e345ad93cf
2. Docker Registry SSL ์ธ์ฆ์ ์ ์ฉํ๊ธฐ
2-1) Master Node - ์ธ์ฆ์ ์์ฑํ๊ธฐ
์ด๋ฒ์๋ SSL ์ธ์ฆ์ด ๊ฐ๋ฅํ Private Registry๋ฅผ ๋ง๋ค๊ฒ ์ต๋๋ค.
๋จผ์ ์ธ์ฆ์ ์์ฑ์ ์งํํฉ๋๋ค. ์ธ์ฆ์ ์์ฑ์ ์ํด /etc/pki/tls/certs ๊ฒฝ๋ก๋ก ์ด๋ํ์ฌ ํ์ผ ๋ชฉ๋ก์ ํ์ธํฉ๋๋ค.
[root@docker-master /]# cd /etc/pki/tls/certs/
[root@docker-master certs]# ls -al
ํฉ๊ณ 12
drwxr-xr-x. 2 root root 117 2์ 29 2020 .
drwxr-xr-x. 5 root root 81 2์ 29 2020 ..
-rw-r--r--. 1 root root 2516 8์ 9 2019 Makefile
lrwxrwxrwx. 1 root root 49 2์ 29 2020 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx. 1 root root 55 2์ 29 2020 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rwxr-xr-x. 1 root root 610 8์ 9 2019 make-dummy-cert
-rwxr-xr-x. 1 root root 829 8์ 9 2019 renew-dummy-cert
์ด์ RSA ํค ํ์ผ์ ์์ฑํ๊ณ , ์์ฑ๋ ํ์ผ์ ํ์ธํฉ๋๋ค. (master.key)
[root@docker-master certs]# openssl genrsa -out master.key 2048
Generating RSA private key, 2048 bit long modulus
............................................................................................................................................+++
.+++
e is 65537 (0x10001)
[root@docker-master certs]# ls -al
ํฉ๊ณ 16
drwxr-xr-x. 2 root root 135 9์ 29 01:14 .
drwxr-xr-x. 5 root root 81 2์ 29 2020 ..
-rw-r--r--. 1 root root 2516 8์ 9 2019 Makefile
lrwxrwxrwx. 1 root root 49 2์ 29 2020 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx. 1 root root 55 2์ 29 2020 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rwxr-xr-x. 1 root root 610 8์ 9 2019 make-dummy-cert
-rw-r--r--. 1 root root 1675 9์ 29 01:14 master.key
-rwxr-xr-x. 1 root root 829 8์ 9 2019 renew-dummy-cert
์ด๋ฒ์๋ CSR ์ธ์ฆ์๋ฅผ ์์ฑ์ฑํ๊ณ , ๋ชฉ๋ก์ ํ์ธํด๋ด ์๋ค. (master.csr)
[root@docker-master certs]# openssl req -new -key master.key -out master.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:KR
State or Province Name (full name) []:seoul
Locality Name (eg, city) [Default City]:seoul
Organization Name (eg, company) [Default Company Ltd]:test
Organizational Unit Name (eg, section) []:test
Common Name (eg, your name or your server's hostname) []:docker-master.test.dom
Email Address []:test@email.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@docker-master certs]# ls -al
ํฉ๊ณ 20
drwxr-xr-x. 2 root root 153 9์ 29 01:17 .
drwxr-xr-x. 5 root root 81 2์ 29 2020 ..
-rw-r--r--. 1 root root 2516 8์ 9 2019 Makefile
lrwxrwxrwx. 1 root root 49 2์ 29 2020 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx. 1 root root 55 2์ 29 2020 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rwxr-xr-x. 1 root root 610 8์ 9 2019 make-dummy-cert
-rw-r--r--. 1 root root 1054 9์ 29 01:17 master.csr
-rw-r--r--. 1 root root 1675 9์ 29 01:14 master.key
-rwxr-xr-x. 1 root root 829 8์ 9 2019 renew-dummy-cert
์ด์ , ์ง์ง ์ธ์ฆ์๋ฅผ ๋ง๋ค์ด์ค๋๋ค.
master.crt๊ฐ ์์ฑ๋์์ต๋๋ค!
[root@docker-master certs]# openssl x509 -req -days 90 -in master.csr -signkey master.key -out master.crt
Signature ok
subject=/C=KR/ST=seoul/L=seoul/O=test/OU=test/CN=docker-master.test.dom/emailAddress=test@email.com
Getting Private key
[root@docker-master certs]# ls -al
ํฉ๊ณ 24
drwxr-xr-x. 2 root root 171 9์ 29 01:19 .
drwxr-xr-x. 5 root root 81 2์ 29 2020 ..
-rw-r--r--. 1 root root 2516 8์ 9 2019 Makefile
lrwxrwxrwx. 1 root root 49 2์ 29 2020 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx. 1 root root 55 2์ 29 2020 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rwxr-xr-x. 1 root root 610 8์ 9 2019 make-dummy-cert
-rw-r--r--. 1 root root 1302 9์ 29 01:19 master.crt
-rw-r--r--. 1 root root 1054 9์ 29 01:17 master.csr
-rw-r--r--. 1 root root 1675 9์ 29 01:14 master.key
-rwxr-xr-x. 1 root root 829 8์ 9 2019 renew-dummy-cert
์ธ์ฆ์ ํ์ผ์ ์ฌ์ฉ ๊ฐ๋ฅํ๋๋ก docker ๊ฒฝ๋ก์ ๋ณต์ฌํ๊ณ docker ๋ฐ๋ชฌ์ ์ฌ์์ ํฉ๋๋ค.
[root@docker-master certs]# mkdir /etc/docker/certs.d
[root@docker-master certs]# cp master.* /etc/docker/certs.d/
[root@docker-master certs]# cp master.crt /etc/pki/ca-trust/source/anchors/
[root@docker-master certs]# update-ca-trust
[root@docker-master certs]# systemctl restart docker
2-2) Master Node - SSL ๋ ์ง์คํธ๋ฆฌ ์์ฑํ๊ธฐ
์ปจํ ์ด๋๋ฅผ ์คํํฉ๋๋ค.
[root@docker-master /]# docker run -d -p 5000:5000 \
--restart=always --name registry\
-v /var/lib/registry:/var/lib/registry\
-v /etc/docker/certs.d:/certs\
-e REGISRTY_HTTP_TLS_CERTIFICATE=/certs/master.crt\
-e REGISTRY_HTTP_TLS_KEY=/certs/master.key registry:2
39facd6dabadcdfafae07efde3a620f1b0a4995a1668b68ef91c5de1839f4e3a
์ปจํ ์ด๋ ๋ชฉ๋ก์ ํ์ธํฉ๋๋ค. Registry ์ปจํ ์ด๋๊ฐ ์ ์ด์๋๊ณ ์๋ค์ :)
[root@docker-master /]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
39facd6dabad registry:2 "/entrypoint.sh /etc…" 11 seconds ago Up 10 seconds 0.0.0.0:5000->5000/tcp registry
2-3) Worker Node - ํ ์คํธ ํ๊ธฐ
์, Worker Node์์ ํ
์คํธ ํด๋ด
์๋ค!.
Master Node์ ์์ฑํ SSL Private Registry๋ฅผ ์ฌ์ฉํด๋ด
์๋ค!
๋จผ์ , ์ด๋ฏธ์ง์ ํ๊ทธ๋ฅผ ๋ฌ์์ค๊ฑด๋ฐ, ํ์์ ์๋์ ๊ฐ์ต๋๋ค.
docker tag <์ต์ > <์ด๋ฏธ์ง ์ด๋ฆ>:<ํ๊ทธ> <์ ์ฅ์ ์ฃผ์, ์ฌ์ฉ์๋ช >/<์ด๋ฏธ์ง ์ด๋ฆ>:<ํ๊ทธ>
๋์ปค ํ๊ทธ๋ฅผ ์๋ก ๋ฌ์์ค์๋ค :)
[root@docker-worker /]# docker tag docker-master.test.dom:5000/httpd:latest docker-master.test.dom:5000/httpd:sslversion
๋์ปค ์ด๋ฏธ์ง๋ฅผ ํ์ธํด๋ณด๋ฉด, ์์์ ์ค์ ํ๊ฒ์ฒ๋ผ ํ๊ทธ๊ฐ ๋ณ๊ฒฝ๋๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-master.test.dom:5000/httpd latest 417af7dc28bc 13 days ago 138MB
docker-master.test.dom:5000/httpd sslversion 417af7dc28bc 13 days ago 138MB
์ด์ ์ด๋ฏธ์ง๋ฅผ Push ํฉ๋๋ค!
[root@docker-worker /]# docker push docker-master.test.dom:5000/httpd:sslversion
The push refers to repository [docker-master.test.dom:5000/httpd]
9f3f3dd7b0c2: Pushed
51eabf53c0c9: Pushed
6ce7826117a0: Pushed
d37da03a9458: Pushed
07cab4339852: Pushed
sslversion: digest: sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db size: 1366
Master ๋
ธ๋์ ๊ตฌ์ฑํด๋์ ๋ ์ง์คํธ๋ฆฌ์ ์ด๋ฏธ์ง๋ฅผ Pushํ์ผ๋, ์ด์ ๋ค์ Pull ํด๋ณผ ์ฐจ๋ก์
๋๋ค.๊ทธ์ ์ worker ๋
ธ๋์ ์ด๋ฏธ์ง๋ฅผ ํ์ธํ๊ณ ์ ์ฒด ์ญ์ ํ๊ฒ ์ต๋๋ค.
docker images ๋ช
๋ น์ด๋ก ํ์ธํ์๋ ์๋ฌด๊ฒ๋ ์๋์ค๋ฉด ๋ฉ๋๋ค!!
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-master.test.dom:5000/httpd latest 417af7dc28bc 13 days ago 138MB
docker-master.test.dom:5000/httpd sslversion 417af7dc28bc 13 days ago 138MB
[root@docker-worker /]# docker rmi -f $(docker images -q)
Untagged: docker-master.test.dom:5000/httpd:latest
Untagged: docker-master.test.dom:5000/httpd:sslversion
Untagged: docker-master.test.dom:5000/httpd@sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db
Deleted: sha256:417af7dc28bc66aa2cc4af18cbfa934cc55f46721b101beac68b9f5c33d7fcb2
Deleted: sha256:2929da9174351249481441a39d499183fa7bb416fbfc2dfc36cdcfca001ace81
Deleted: sha256:46fba7aa125a55a717a218e2750c991bbf4d9e7bb66c56bacde76338a5b38f16
Deleted: sha256:a8151056fecd4987dd3fcde6579e8d34b72c1e39dfd5ac63209cffa0b0befb08
Deleted: sha256:97635989e45ed57deef09cd09be52d008a073f2e1e045a1ba91956fbc2db2961
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
๋์ปค ์ด๋ฏธ์ง๋ฅผ Pull ํด์ ์ด๋ฏธ์ง๋ฅผ ์ ๋ฐ์์ค๋์ง ํ์ธํฉ๋๋ค :)
์์ฃผ ์ ๋ฐ์์ค๋ค์!!
[root@docker-worker /]# docker pull docker-master.test.dom:5000/httpd:sslversion
sslversion: Pulling from httpd
d121f8d1c412: Already exists
9cd35c2006cf: Pull complete
b6b9dec6e0f8: Pull complete
fc3f9b55fcc2: Pull complete
802357647f64: Pull complete
Digest: sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db
Status: Downloaded newer image for docker-master.test.dom:5000/httpd:sslversion
docker-master.test.dom:5000/httpd:sslversion
[root@docker-worker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-master.test.dom:5000/httpd sslversion 417af7dc28bc 13 days ago 138MB
2-4) Master Node - ๋ ์ง์คํธ๋ฆฌ ์ปจํ ์ด๋ ์ญ์ ํ๊ธฐ
์ ์ด์ ํ
์คํธ๊ฐ ์๋ฃ๋์์ผ๋ ์ปจํ
์ด๋๋ฅผ ์ญ์ ํฉ๋๋ค :)
Master ๋
ธ๋์์ ์ปจํ
์ด๋๋ฅผ ์ญ์ ํด์ฃผ์ธ์.
[root@docker-master /]# docker rm -f $(docker ps -aq)
39facd6dabad
3. Docker Registry SSH ์ธ์ฆ์ + ์ฌ์ฉ์ ์ธ์ฆ ์ ์ฉํ๊ธฐ
์ง๊ธ๊น์ง Master ๋
ธ๋์ ๋์ปค ์ด๋ฏธ์ง ์ ์ฅ์๋ฅผ ๋ง๋ค๊ณ ์ฌ์ฉํด๋ดค๊ณ , HTTPS๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก SSL์ธ์ฆ์๋ฅผ ์ ์ฉํด๋ดค์ต๋๋ค.
๋ง์ง๋ง์ผ๋ก, ์ฌ์ฉ์ ์ธ์ฆ๋ ํจ๊ป ์ฌ์ฉํ ์ ์๋๋ก ํฉ๋๋ค :)
3-1) Master Node - ์ฌ์ฉ์ ์ธ์ฆ ์ค์ ํ๊ธฐ
์ฌ์ฉ์ ์ธ์ฆ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ httpd ์์ ์ ๊ณตํ๋ httpd-tools ๋ฅผ ์ฌ์ฉํฉ๋๋ค :)
๋จผ์ ์ฌ์ฉ์ ์ธ์ฆ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํฉ๋๋ค.
[root@docker-master /]# yum install httpd-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-93.el7.centos will be installed
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-tools-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-tools-2.4.6-93.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================
Installing:
httpd-tools x86_64 2.4.6-93.el7.centos base 92 k
Installing for dependencies:
apr x86_64 1.4.8-5.el7 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
Transaction Summary
=============================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 288 k
Installed size: 584 k
Is this ok [y/d/N]: y
Downloading packages:
(1/3): apr-1.4.8-5.el7.x86_64.rpm | 103 kB 00:00:00
(2/3): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
(3/3): httpd-tools-2.4.6-93.el7.centos.x86_64.rpm | 92 kB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------
Total 3.1 MB/s | 288 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-5.el7.x86_64 1/3
Installing : apr-util-1.5.2-6.el7.x86_64 2/3
Installing : httpd-tools-2.4.6-93.el7.centos.x86_64 3/3
Verifying : apr-1.4.8-5.el7.x86_64 1/3
Verifying : httpd-tools-2.4.6-93.el7.centos.x86_64 2/3
Verifying : apr-util-1.5.2-6.el7.x86_64 3/3
Installed:
httpd-tools.x86_64 0:2.4.6-93.el7.centos
Dependency Installed:
apr.x86_64 0:1.4.8-5.el7 apr-util.x86_64 0:1.5.2-6.el7
Complete!
htpasswd ๋ช
๋ น์ด๋ก ์ฌ์ฉ์๋ฅผ ์ถ๊ฐํด์ค๋๋ค.
์กฐ๊ธ์ด๋ฐ๊ฐ ์ด ์ฌ์ฉ์๋ก ๋ก๊ทธ์ธ ํ
์คํธ๋ฅผ ์งํํ ์์ ์ด๋, ๊ณ์ ๊ณผ ๋น๋ฐ๋ฒํธ๋ฅผ ๊น๋จน์ง ์๊ฒ ์ฃผ์ํ์ธ์.
[root@docker-master /]# htpasswd -Bc /etc/docker/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin
3-2) Master Node - SSL + ์ธ์ฆ ๊ธฐ๋ฅ์ด ์ ์ฉ๋ ๋ ์ง์คํธ๋ฆฌ ์์ฑ
SSL ๋ฐ ์ฌ์ฉ์์ธ์ฆ ๊ธฐ๋ฅ์ด ์ถ๊ฐ๋ Registry ์ปจํ ์ด๋๋ฅผ ์์ฑํฉ๋๋ค.
[root@docker-master /]# docker run -d -p 5000:5000 --restart=always --name registry \
-v /var/lib/registry:/var/lib/registry \
-v /etc/docker/certs.d:/certs \
-v /etc/docker:/auth \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/master.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/master.key \
-e REGISTRY_AUTH=htpasswd \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/.htpasswd \
-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" registry:2
์ ์๋์ํ๋์ง๋ ํ์ธํฉ๋๋ค :)
์ ๋์ํ๋ค์! ์ด์ ๋ค์ ๋จ๊ณ๋ก ๋์ด๊ฐ์ ํ
์คํธ ํด๋ด
์๋ค.
[root@docker-master /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2bf8c98f110d registry:2 "/entrypoint.sh /etc…" About a minute ago Up About a minute 0.0.0.0:5000->5000/tcp registry
3-3) Worker Node - ํ ์คํธ ํ๊ธฐ!
๋จผ์ docker login <๋ ์ง์คํธ๋ฆฌ> ๋ช
๋ น์ด๋ก ๋ก๊ทธ์ธ ํฉ๋๋ค.
๋ง์ฝ ๋ก๊ทธ์ธํ์ง ์๊ณ ๋ ์ง์คํธ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๋ฉด ์๋ฌ๊ฐ ๋์ต๋๋ค :) ์ ์์ด์์.
์์์ ๋ง๋ค์๋ admin ์ฌ์ฉ์๋ก ๋ก๊ทธ์ธ ํฉ๋๋ค.
[root@docker-worker /]# docker login docker-master.test.dom:5000
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
ํ ์คํธ ์ ์ Worker ๋ ธ๋์ ์๋ ์ด๋ฏธ์ง๋ฅผ ๋ค ์ญ์ ํฉ๋๋ค.
[root@docker-worker /]# docker rmi -f $(docker images -q)
Untagged: docker-master.test.dom:5000/httpd:sslversion
Untagged: docker-master.test.dom:5000/httpd@sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db
Deleted: sha256:417af7dc28bc66aa2cc4af18cbfa934cc55f46721b101beac68b9f5c33d7fcb2
Deleted: sha256:2929da9174351249481441a39d499183fa7bb416fbfc2dfc36cdcfca001ace81
Deleted: sha256:46fba7aa125a55a717a218e2750c991bbf4d9e7bb66c56bacde76338a5b38f16
Deleted: sha256:a8151056fecd4987dd3fcde6579e8d34b72c1e39dfd5ac63209cffa0b0befb08
Deleted: sha256:97635989e45ed57deef09cd09be52d008a073f2e1e045a1ba91956fbc2db2961
SSL ๋ฐ ์ฌ์ฉ์ ์ธ์ฆ ๊ธฐ๋ฅ์ด ์ถ๊ฐ๋ ๋ ์ง์คํธ๋ฆฌ์์ ์ ์์ ์ผ๋ก ์ปจํ
์ด๋ ์ด๋ฏธ์ง๊ฐ ๋ค์ด๋ฐ์์ง๋ค์ :)
[root@docker-worker /]# docker pull docker-master.test.dom:5000/httpd:sslversion
sslversion: Pulling from httpd
d121f8d1c412: Already exists
9cd35c2006cf: Pull complete
b6b9dec6e0f8: Pull complete
fc3f9b55fcc2: Pull complete
802357647f64: Pull complete
Digest: sha256:ee876fb8588d58d25eb95840c5d81d211f0ebf238c7c10cbaea10861f6a027db
Status: Downloaded newer image for docker-master.test.dom:5000/httpd:sslversion
docker-master.test.dom:5000/httpd:sslversion
์ฑ๊ณต์
๋๋ค!
๊ณ ์ํ์
จ์ต๋๋ค๐