docker registry 사설ip 환경으로 사용하기

mhlee·2021년 3월 11일
1

docker registry 사설 ip환경 사용

0. 시작하며

IDC 환경에서 docker를 사용하려 한다.
망분리(?)라는 요상한 환경에서 외부접속이 쉽지 않다.
결국 내부에 docker registry를 구축하기로 결정했다.

1. docker registry

# docker registry를 가져온다.
docker pull registry

# registry 기동
docker run -dit --name docker-registry -p 5000:5000 registry

2. docker registry test

# hello-world 이미지를 가져온다.
docker pull hello-world

# hello-world 이미지를 private registry의 이미지로 사용할수 있게 태깅한다.
docker tag hello-world:latest <your-ip>:5000/hello-world

# 이미지를 확인,  새로운 이미지가 생성된것을 확인할수 있다.
docker images
psadmin@backup01:~$ docker images

REPOSITORY                        TAG       IMAGE ID       CREATED       SIZE
<your-ip>:5000/hello-world        latest    d1165f221234   5 days ago    13.3kB
hello-world                       latest    d1165f221234   5 days ago    13.3kB
registry                          latest    5c4008a25e05   2 weeks ago   26.2MB

# 이미지 푸쉬
docker push <your-ip>:5000/hello-world

마지막 명령에서 아래와 같은 에러가 발생할 것이다.
localhost 인 경우는 상관없으나, remote인 경우는 https가 필수로 적용되어야 한다고 한다.

Get https://<your-ip>:5000/v1/_ping: http: server gave HTTP response to HTTPS client

3. insecure 옵션 적용

정상적이라면 SSL 인증서를 적용해서, https로 서비스 해야 한다.
하지만, 앞서도 언급했지만 외부와 단절된 네트워크에서 사용하는것이 목적이고, 사설 ip를 통해서 접속한다.

docker 설정화일 디렉토리에 아래 deamon.json으로 파일을 만들고 아래 내용을 추가한다.

{
"insecure-registries" : ["myregistrydomain.com:5000"]
}

출처 : https://docs.docker.com/registry/insecure/

그리고 docker를 재시작 한다.
pull, push 명령이 이상없이 동작하는지 확인한다.
추가로, 위 설정화일은 docker registry 기동되는 서버는 물론, docker를 사용하는 모든 서버에 적용해 주어야 한다.

이글은 아래 글들을 참고해서 작성했습니다.
https://docs.docker.com/registry/insecure/
https://novemberde.github.io/2017/04/09/Docker_Registry_0.html

4. 외부 볼륨 연결하기

마지막으로, 외부 볼륨을 연결해서 사용하는 경우, 아래와 같이 -v 옵션을 사용해서 마운트 시키면 된다.

docker run --name docker-registry \
-d --restart=always \
-p 5000:5000 \
-v /data/docker-registry:/var/lib/registry/docker/registry/v2 \
registry:latest
profile
삽질하는 개발자

0개의 댓글