Docker 개인용 레지스트리는 대역폭 절약(외부 네트워크가 느리거나 연결 불가능한 경우)과 시스템 커스터마이징을 위해 사용됩니다.
(1). 환경 설정
레지스트리 서버: 192.168.5.101 Docker 클라이언트: 192.168.5.102
Docker 클라이언트는 레지스트리 서버를 통해 이미지를 pull/push 합니다.
두 서버 모두 Docker 설치가 필요하며, 자세한 설치 방법은 "Docker 컨테이너(一)——Docker의 소개와 배포"를 참조하세요.
(2). docker-registry를 이용한 개인용 레지스트리 생성
docker-registry는 공식 도구로 개인용 이미지 레지스트리 생성에 사용됩니다.
방법: registry 이미지를 다운로드하여 Docker 컨테이너 실행
1)레지스트리 서버 설정
방화벽과 SELinux 비활성화
[root@레지스트리서버 ~]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@레지스트리서버 ~]# cat /etc/sysconfig/selinux
SELINUX=disabled //disabled로 변경
SELINUXTYPE=targeted
[root@레지스트리서버 ~]# reboot //시스템 재시작
이미지 가져오기
//온라인 이미지 가져오기, 가속기 주소 사용 필수
[root@레지스트리서버 ~]# docker pull registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@레지스트리서버 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest f32a97de94e1 6개월 전 25.8MB
//로컬 이미지 가져오기
[root@레지스트리서버 ~]# docker load -i registry.tar
기본적으로 registry 프로그램은 이미지 정보를 /var/lib/registry에 저장합니다. 컨테이너가 삭제되면 저장된 이미지도 함께 삭제됩니다. 따라서 일반적으로 -v 옵션을 사용하여 호스트의 디렉토리를 컨테이너의 /var/lib/registry에 마운트합니다. 또한 프로그램은 기본적으로 5000 포트를 사용하므로 -p 옵션으로 포트를 매핑합니다.
[root@레지스트리서버 ~]# docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry registry:latest
33405dbe1d5435172aea0544449629ef16f18b58d9c2fdb06f8fcdad55867f5b
[root@레지스트리서버 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33405dbe1d54 registry:latest "/entrypoint.sh /etc…" 11초 전 Up 10초 0.0.0.0:5000->5000/tcp confident_kare
[root@레지스트리서버 ~]# yum -y install net-tools
[root@레지스트리서버 ~]# netstat -antup | grep 5000
tcp6 0 0 :::5000 :::* LISTEN 1744/docker-proxy
Windows 브라우저로 192.168.5.101:5000/v2/_catalog 접속
레지스트리에 이미지가 없으므로 대괄호 []가 비어 있습니다.
2)클라이언트에서 개인용 레지스트리 사용
사용 전, 클라이언트에서 테스트용 이미지를 다운로드합니다. 로컬 이미지가 있다면 직접 가져올 수 있습니다. 여기서는 centos와 busybox를 다운로드했습니다. BusyBox는 300개 이상의 일반적인 Linux 명령과 도구를 통합한 소프트웨어입니다. 공식 사이트: https://busybox.net/. 두 이미지를 다운로드한 이유는 설정 파일과 서비스 파일을 수정하여 Docker 가속 노드가 개인용 레지스트리를 가리키도록 테스트하기 위함입니다.
[root@클라이언트 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
d8d02d457314: Pull complete
Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@클라이언트 ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
7c9d20b9b6cd: Pull complete
Digest: sha256:fe301db49df08c384001ed752dff6d52b4305a73a7f608f21528048e8a08b51e
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest
[root@클라이언트 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb 2주 전 1.22MB
centos latest 67fa590cfc1c 4주 전 202MB
설정 파일 또는 서비스 파일 수정하여 Docker 가속 노드가 개인용 레지스트리를 가리키도록 설정
//설정 파일 수정
[root@클라이언트 ~]# vim /etc/docker/daemon.json
{
"insecure-registries": ["192.168.5.101:5000"]
}
[root@클라이언트 ~]# systemctl restart docker
//서비스 파일 수정
[root@클라이언트 ~]# vim /usr/lib/systemd/system/docker.service
//14행 수정
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
--insecure-registry 192.168.5.101:5000
[root@클라이언트 ~]# systemctl daemon-reload
[root@클라이언트 ~]# systemctl restart docker
기존 이미지에 태그 추가
[root@클라이언트 ~]# docker tag centos:latest 192.168.5.101:5000/centos:latest
[root@클라이언트 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb 2주 전 1.22MB
192.168.5.101:5000/centos latest 67fa590cfc1c 4주 전 202MB
centos latest 67fa590cfc1c 4주 전 202MB
태그가 추가된 이미지를 개인용 레지스트리에 업로드
[root@클라이언트 ~]# docker push 192.168.5.101:5000/centos:latest
The push refers to repository [192.168.5.101:5000/centos]
877b494a9f30: Pushed
latest: digest: sha256:a36b9e68613d07eec4ef553da84d0012a5ca5ae4a830cf825bb68b929475c869 size: 529
브라우저 새로고침 시 업로드된 이미지 확인 가능
업로드가 가능하므로 다운로드 기능도 테스트
[root@클라이언트 ~]# docker images //기존 이미지 확인
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.5.101:5000/busybox latest 19485c79a9bb 2주 전 1.22MB
busybox latest 19485c79a9bb 2주 전 1.22MB
192.168.5.101:5000/centos latest 67fa590cfc1c 4주 전 202MB
centos latest 67fa590cfc1c 4주 전 202MB
[root@클라이언트 ~]# docker rmi 192.168.5.101:5000/busybox:latest //개인용 이미지 삭제
Untagged: 192.168.5.101:5000/busybox:latest
Untagged: 192.168.5.101:5000/busybox@sha256:dd97a3fe6d721c5cf03abac0f50e2848dc583f7c4e41bf39102ceb42edfd1808
[root@클라이언트 ~]# docker images //다시 확인
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb 2주 전 1.22MB
192.168.5.101:5000/centos latest 67fa590cfc1c 4주 전 202MB
centos latest 67fa590cfc1c 4주 전 202MB
[root@클라이언트 ~]# docker pull 192.168.5.101:5000/busybox //이미지 다운로드
Using default tag: latest
latest: Pulling from busybox
Digest: sha256:dd97a3fe6d721c5cf03abac0f50e2848dc583f7c4e41bf39102ceb42edfd1808
Status: Downloaded newer image for 192.168.5.101:5000/busybox:latest
192.168.5.101:5000/busybox:latest
[root@클라이언트 ~]# docker images //확인
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.5.101:5000/busybox latest 19485c79a9bb 2주 전 1.22MB
busybox latest 19485c79a9bb 2주 전 1.22MB
192.168.5.101:5000/centos latest 67fa590cfc1c 4주 전 202MB
centos latest 67fa590cfc1c 4주 전 202MB
[root@클라이언트 ~]# docker run 192.168.5.101:5000/busybox:latest echo "hello world" //테스트
hello world
(3). harbor를 이용한 개인용 레지스트리 생성
harbor는 VMware에서 개발한 기업용 Docker Registry 관리 프로젝트로, RBAC 권한 관리, LDAP, 로그 감사, 관리 인터페이스, 자가 등록, 이미지 복제 및 중국어 지원 기능을 포함합니다. 공식 사이트: https://github.com/goharbor/harbor
주의: harbor 설치에는 6GB 이상의 공간과 2GB 이상의 메모리가 필요합니다.
1)레지스트리 서버에 harbor 설치
pip 설치 및 업데이트, docker-compose 설치
[root@레지스트리서버 ~]# yum -y install python-pip
[root@레지스트리서버 ~]# pip install --upgrade pip
[root@레지스트리서버 ~]# pip install -U -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose
GitHub에서 harbor 설치 패키지 다운로드 및 설치. 다운로드 주소: https://github.com/goharbor/harbor/releases
[root@레지스트리서버 ~]# tar xf harbor-offline-installer-v1.9.0.tgz -C /usr/local/src/
[root@레지스트리서버 ~]# cd /usr/local/src/harbor/
[root@레지스트리서버 harbor]# vim harbor.yml
hostname: 192.168.5.101 //5행, IP 주소로 변경
harbor_admin_password: 123456 //27행, 관리자 UI 로그인 비밀번호
data_volume: /data //40행, harbor 데이터 저장 위치
[root@레지스트리서버 harbor]# ./prepare//설치 환경 초기화
[root@레지스트리서버 harbor]# ./install.sh //기본 설치
......
[Step 3]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating redis ... done
Creating registry ... done
Creating harbor-db ... done
Creating registryctl ... done
Creating harbor-portal ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.5.101.
For more details, please visit https://github.com/goharbor/harbor .
[root@레지스트리서버 harbor]# docker images //확인
REPOSITORY TAG IMAGE ID CREATED SIZE
goharbor/prepare dev 265a282fa199 24시간 전 147MB
goharbor/chartmuseum-photon v0.9.0-v1.9.0 00c12627cbd7 10일 전 131MB
goharbor/harbor-migrator v1.9.0 75d4de5e0f16 10일 전 362MB
goharbor/redis-photon v1.9.0 3249afaa9965 10일 전 109MB
goharbor/clair-photon v2.0.9-v1.9.0 e54ad567c58f 10일 전 165MB
goharbor/notary-server-photon v0.6.1-v1.9.0 2cdecba59f38 10일 전 138MB
goharbor/notary-signer-photon v0.6.1-v1.9.0 973378593def 10일 전 135MB
goharbor/harbor-registryctl v1.9.0 30a01bf0f4df 10일 전 99.6MB
goharbor/registry-photon v2.7.1-patch-2819-v1.9.0 32571099a9fe 10일 전 82.3MB
goharbor/nginx-photon v1.9.0 f933d62f9952 10일 전 43.9MB
goharbor/harbor-log v1.9.0 28e27d511335 10일 전 82.6MB
goharbor/harbor-jobservice v1.9.0 f3cd0b181a89 10일 전 141MB
goharbor/harbor-core v1.9.0 f2814ed8aadd 10일 전 155MB
goharbor/harbor-portal v1.9.0 0778d4c5d27e 10일 전 51.3MB
goharbor/harbor-db v1.9.0 a809e14d2d49 10일 전 147MB
goharbor/prepare v1.9.0 aa594772c1e8 10일 전 147MB
Windows 브라우저로 192.168.5.101 접속, 계정 admin, 비밀번호 123456
기본 프로젝트가 있으며 새로 생성 가능
2)클라이언트에서 개인용 레지스트리 사용
테스트용 이미지 두 개 다운로드
[root@클라이언트 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
d8d02d457314: Pull complete
Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@클라이언트 ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
7c9d20b9b6cd: Pull complete
Digest: sha256:fe301db49df08c384001ed752dff6d52b4305a73a7f608f21528048e8a08b51e
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest
[root@클라이언트 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb 2주 전 1.22MB
centos latest 67fa590cfc1c 4주 전 202MB
설정 파일 또는 서비스 파일 수정하여 Docker 가속 노드가 개인용 레지스트리를 가리키도록 설정
//설정 파일 수정
[root@클라이언트 ~]# vim /etc/docker/daemon.json
{
"insecure-registries": ["192.168.5.101"]
}
[root@클라이언트 ~]# systemctl restart docker
//서비스 파일 수정
[root@클라이언트 ~]# vim /usr/lib/systemd/system/docker.service
//14행 수정
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
--insecure-registry 192.168.5.101
[root@클라이언트 ~]# systemctl daemon-reload
[root@클라이언트 ~]# systemctl restart docker
기존 이미지에 태그 추가
[root@클라이언트 ~]# docker login 192.168.5.101 //개인용 레지스트리 로그인
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
[root@클라이언트 ~]# docker tag centos:latest 192.168.5.101/library/centos:latest
[root@클라이언트 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb 2주 전 1.22MB
192.168.5.101/library/centos latest 67fa590cfc1c 4주 전 202MB
centos latest 67fa590cfc1c 4주 전 202MB
태그가 추가된 이미지를 개인용 레지스트리에 업로드
[root@클라이언트 ~]# docker push 192.168.5.101/library/centos:latest
The push refers to repository [192.168.5.101/library/centos]
877b494a9f30: Pushed
latest: digest: sha256:a36b9e68613d07eec4ef553da84d0012a5ca5ae4a830cf825bb68b929475c869 size: 529
브라우저 새로고침 시 레지스트리 이미지 수가 2로 변경됨
업로드 테스트 후 다운로드 테스트
[root@클라이언트 ~]# docker images //기존 이미지 확인
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.5.101/library/busybox latest 19485c79a9bb 2주 전 1.22MB
busybox latest 19485c79a9bb 2주 전 1.22MB
centos latest 67fa590cfc1c 4주 전 202MB
192.168.5.101/library/centos latest 67fa590cfc1c 4주 전 202MB
[root@클라이언트 ~]# docker rmi 192.168.5.101/library/busybox:latest //이미지 삭제
Untagged: 192.168.5.101/library/busybox:latest
Untagged: 192.168.5.101/library/busybox@sha256:dd97a3fe6d721c5cf03abac0f50e2848dc583f7c4e41bf39102ceb42edfd1808
[root@클라이언트 ~]# docker images //다시 확인
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb 2주 전 1.22MB
192.168.5.101/library/centos latest 67fa590cfc1c 4주 전 202MB
centos latest 67fa590cfc1c 4주 전 202MB
[root@클라이언트 ~]# docker pull 192.168.5.101/library/busybox:latest //다운로드
latest: Pulling from library/busybox
Digest: sha256:dd97a3fe6d721c5cf03abac0f50e2848dc583f7c4e41bf39102ceb42edfd1808
Status: Downloaded newer image for 192.168.5.101/library/busybox:latest
192.168.5.101/library/busybox:latest
[root@클라이언트 ~]# docker images //확인
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.5.101/library/busybox latest 19485c79a9bb 2주 전 1.22MB
busybox latest 19485c79a9bb 2주 전 1.22MB
192.168.5.101/library/centos latest 67fa590cfc1c 4주 전 202MB
centos latest 67fa590cfc1c 4주 전 202MB