본문 바로가기
운영_설치/도커

private registry 사용하기

by 써드아이 2020. 3. 21.

$ docker volume create registry-volume
$ docker pull registry
$ docker run -d --restart=always --name private-registry -p 5000:5000 -v registry-volume:/var/lib/registry registry


$ docker tag downloaded_img:latest localhost:5000/downloaded_img:latest
$ docker push localhost:5000/downloaded_img:latest


$ docker pull localhost:5000/downloaded_img:latest

$ docker run localhost:5000/downloaded_img:latest


도커는 저장소의 이용ㅇ https를 사용하는데 registry 가 http만 지원하기 때문에 push 할 때 오류가 발생한다.
도커 데몬을 http로 저장소에 접근하도록 실행한다.

/etc/conf.d/docker

DOCKER_OPTS="--insecure-registry localhost:5000"



$ curl -X GET localhost:5000/v2/_catalog # 이미지 조회
$ curl -X GET localhost:5000/v2/downloaded_img/tags/list # 이미지의 태그 조회

$ curl -v --silent -H \ # digest 구하기
"Accept: application/vnd.docker.distribution.manifest.v2+json" 2>&1 \
-X GET localhost:5000/v2/downloaded_img/manifests/latest | \
grep Docker-Content-Digest | awk '{print ($3)}'

$ curl -v --silent -H \ # 이미지 삭제
"Accept: application/vnd.docker.distribution.manifest.v2+json" 2>&1 \
-X DELETE localhost:5000/v2/downloaded_img/manifests/[sha256:]

$ docker exec -it private-registry registry \ # garbage collection
garbage-collect /etc/docker/registry/config.yml

* 그런데 안된다.
그래서 레지스트리 안의 실제 디렉토리를 삭제해야한다

$ docker exec -it private-registry /bin/sh

cd /var/lib/registry/docker/registry/v2/repositories/
rm -rf "삭제할 이미지 dir"
exit

/bin/bash가 아니라 /bin/sh 임을 명심하자

그렇지 않으면 다음과 같은 오류가 발생한다.

OCI runtime exec failed: exec failed: container_linux.go:346: starting 
container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file 
or directory": unknown