본문 바로가기
요즘공부

[도커&쿠버네티스] 교육 3일차_ Docker 서버 2개 운용

by 게으른 피글렛 2025. 3. 18.
반응형

1. Docker 서버

도커 서버가 현재

1. Ubuntu 22.04 : 192.168.50.10

2. Centos9s :  192.168.50.20

생성되어있음

 

Ubuntu 22.04  서버를 메인으로 사용

Centos9s 서버는 registry 용으로 사용하여 테스트 예정

 

기존 서버에 있던 내용을 전부 삭제 후 실행

 

통신여부 확인 > 도메인으로도 통신할 수 있도록 설정

통신 여부 확인함

서로 통신이 되고 있음

 

도메인 등록

마지막에 192.168.50.20 registry.example.com 도메인 추가함

vagrant@ubuntu2204:~$ sudo vi /etc/hosts
vagrant@ubuntu2204:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu2204.localdomain

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.0.1 ubuntu2204.localdomain
192.168.50.20 registry.example.com

 

 

 

****Centos9s****

registry 로 설정하기 위해 도커 hub에서 내용 확인

https://hub.docker.com/_/registry

 

registry - Official Image | Docker Hub

Docker Official Images are a curated set of Docker open source and drop-in solution repositories. Why Official Images? These images have clear documentation, promote best practices, and are designed for the most common use cases.

hub.docker.com

 

 

[vagrant@centos ~]$ docker run -d -p 5000:5000 --restart always --name registry registry:2
[vagrant@centos ~]$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
registry     2         26b2eb03618e   17 months ago   25.4MB

 

 

 

****Ubuntu 22.04****

 

비보안(insecure) 레지스트리 추가

* docker registry 에 엑세스 할때 기본적으로 보안연결(https)을 사용하게 된다.
*. 인증서설치 없이 접속하기위해서는 아래처럼 비보안연결 설정 파일을 클라이언트에서 만들면 된다.

-> vi /etc/docker/daemon.json

vagrant@ubuntu2204:~$ sudo vi /etc/docker/daemon.json
vagrant@ubuntu2204:~$ cat /etc/docker/daemon.json
{"insecure-registries": ["registry.example.com:5000"] }

 

에러가 날 수도 있으므로 재시작

vagrant@ubuntu2204:~/work$ sudo systemctl restart docker

 

 

로컬의 mariadb 이미지를 registry.example.com:5000 서버로 **업로드(upload)**하는 명령어

vagrant@ubuntu2204:~/work$ docker push registry.example.com:5000/mariadb
Using default tag: latest
The push refers to repository [registry.example.com:5000/mariadb]
An image does not exist locally with the tag: registry.example.com:5000/mariadb

 

 

 

 

****Centos9s****

레지스트리가 제대로 저장이 되는지 테스트

[vagrant@centos ~]$ sudo find /var/lib/docker/ -name mariadb
/var/lib/docker/overlay2/919549e7c11f4d596eb2808513c073224ccc207f7e22cd659e8923d89c474524/diff/etc/apt/preferences.d/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/etc/init.d/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/etc/logrotate.d/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/usr/bin/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/usr/share/mariadb

 

 

 

****Ubuntu 22.04****

pull??

push???

# 'mariadb:latest' 이미지를 로컬 레지스트리(5000번 포트)에 'registry.example.com:5000/mariadb' 태그로 지정
vagrant@ubuntu2204:~/work$ docker tag mariadb:latest registry.example.com:5000/mariadb

# 'registry.example.com:5000/mariadb' 이미지를 로컬 레지스트리로 푸시(업로드)하는 명령
vagrant@ubuntu2204:~/work$ docker push registry.example.com:5000/mariadb

 

Docker Registry API를 통해 레지스트리에 저장된 이미지 목록을 조회하는 요청

vagrant@ubuntu2204:~/work$ curl -X GET registry.example.com:5000/v2/_catalog    
{"repositories":["mariadb"]}

 

 

 

****Centos9s****

레지스트리 저장된 내용을 확인

정상적으로 내용이 저장되고 있음을 확인

[vagrant@centos ~]$ sudo find /var/lib/docker/ -name mariadb
/var/lib/docker/volumes/f58fdfa94ce3c09b6ecb9bad270830541fa6ad0a755ead7331268f7144ca97ba/_data/docker/registry/v2/repositories/mariadb
/var/lib/docker/overlay2/919549e7c11f4d596eb2808513c073224ccc207f7e22cd659e8923d89c474524/diff/etc/apt/preferences.d/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/etc/init.d/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/etc/logrotate.d/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/usr/bin/mariadb
/var/lib/docker/overlay2/eed6f730694c0795dfe84a58b3cd5f5fc82043c7d56495025579e5dcee0dc539/diff/usr/share/mariadb

 

 

 

 

 

 

 

 

 

 

 

 

반응형