본문 바로가기
DevOps

Private docker registry 구성하기

by omegaduck 2022. 5. 30.

Installation

Server 설정

pull registry Image

s2motion@s2motion-52700:/$ sudo docker pull registry:latest

ssl 접속이 기본이므로 개인적인 구축 저장소 사용을 위해 --insecure-registry 옵션 추가

s2motion@s2motion-52700:/$
sudo vi /etc/init.d/docker
DOCKERD=/usr/bin/dockerd
# This is the pid file managed by docker itself
DOCKER_PIDFILE=/var/run/$BASE.pid
# This is the pid file created/managed by start-stop-daemon
DOCKER_SSD_PIDFILE=/var/run/$BASE-ssd.pid
DOCKER_LOGFILE=/var/log/$BASE.log
DOCKER_OPTS=--insecure-registry localhost:5000

ssl 인증서 설치

  • SSL 생성 by OpenSSL
$ openssl genrsa -out server.key 2048
  • 인증서 서명 요청
$ openssl req -new -key server.key -out server.csr
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]:omegaduck
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server\'s hostname) []:xxxx.xxxx.com
Email Address []:
  • 공개키 생성
$openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

  • 인증서 설치
#현구동 방법은 2번 방법으로 진행했으나 1번방법으로 만 구성해도 되는지 테스트 필요
1번 방법)################
s2motion@s2motion-52700:~/anaconda3/bin$ sudo cp server.crt /usr/share/ca-certificates/ s2motion@s2motion-52700:~/anaconda3/bin$ echo "server.crt" | sudo tee -a /etc/ca-certificates.conf s2motion@s2motion-52700:~/anaconda3/bin$ sudo update-ca-certificates Updating certificates in /etc/ssl/certs... 1 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... done. 2번 방법)################# $mkdir /home/s2motion/certs #crt, key, csr 화일을 /home/s2motion/certs cp server.* /home/s2motion/certs  

접속 인증을 위한 구성

s2motion@s2motion-52700:~$ mkdir auth $ sudo docker run --entrypoint htpasswd registry:2 -Bbn s2motion [password] > auth/htpasswd

Docker service 재시작

$sudo service docker restart

Registry Image 구동

#공백이 있는 경우는 option 처리시 ""사용 $ sudo docker run -d -p 5000:5000 --restart=always --name docker-registry \
  -v /home/s2motion/certs:/certs \
  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.crt \
  -e REGISTRY_HTTP_TLS_KEY=/certs/server.key \   -v /home/s2motion/auth:/auth \   -e REGISTRY_AUTH=htpasswd \   -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \   -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \   registry  

Client  설정 및 push/pull 테스트

리눅스 계열 클라이언트는 3번의 인증서 설치 단계 및 재기동 단계를 적용해야함.
단, windows는 가상머신 기반이므로 다음과 같이 처리

Client Side (for windows)

서버의 인증서 클라이언트로 다운로드

서버 인증서 가상머신으로 복사

$ docker-machine scp server.crt s2nano:/home/docker/
$ docker-machine ssh s2nano  
docker@s2nano:~$ mkdir /etc/docker/certs.d  
docker@s2nano:~$ sudo mkdir /etc/docker/certs.d
docker@s2nano:~$ sudo mkdir /etc/docker/certs.d/xxxx.xxxx.com
docker@s2nano:~$ sudo cp /home/docker/server.crt /etc/docker/certs.d/xxxx.xxxx.com/ca.cert

docker-machine restart

$ docker-machine restart s2nano

push/pull test

위서버에 인증을 사용하고 있으므로
#우선 docker login
$docker login xxxx.xxxx.com:5000   #hello-world image로 테스트
$ docker pull hello-world $ docker tag hello-world xxxx.xxxx.com:5000/hello-world
$ docker push xxxx.xxxx.com:5000/hello-world

이와 같이 진행할 경우 아래 에러 발생

The push refers to repository [xxxx.xxxx.com:5000/hello-world] Get https://xxxxx.xxxx.com:5000/v2/: x509: certificate signed by unknown authority

kitematic을 사용하고 있다면 아래와 같은 docker-machine의  /var/lib/boot2docker/profile 파일에 EXTRA_ARGS 에 –insecure-registry를 추가

docker-machine ssh s2nano sudo vi /var/lib/boot2docker/profile   EXTRA_ARGS=' --label provider=virtualbox --insecure-registry xxxx.xxxx.com:5000   ' CACERT=/var/lib/boot2docker/ca.pem DOCKER_HOST='-H tcp://0.0.0.0:2376' DOCKER_STORAGE=aufs DOCKER_TLS=auto SERVERKEY=/var/lib/boot2docker/server-key.pem SERVERCERT=/var/lib/boot2docker/server.pem  

docker-machine restart

$ docker-machine restart s2nano

pull & push test 다시

  • push
$ docker push xxxx.xxxx.com:5000/hello-world

         결과

The push refers to repository [xxxx.xxxx.xxxx:5000/hello-world] af0b15c8625b: Pushed  latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
  • pull
$ docker pull xxxx.xxxx.com:5000/hello-world

      결과

pull 성공  
  • 인증서가 설치되어 있지 않은 docker-machine에 EXTRA_ARGS 에 –insecure-registry를 추가만 하고 인증되는지 확인 (되버림.. 사용자 인증하는 방법 추가 설정 필요)

'DevOps' 카테고리의 다른 글

Git Commands  (0) 2022.05.30