본문 바로가기

리눅스

[리눅스] private docker registry 사용 방법

728x90

private docker registry 사용 방법

레지스트리 로그인

docker login -u admin https://dockerhub.scbyun.com:5000

$ docker login -u admin https://dockerhub.scbyun.com:5000
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

이미지 다운로드(docker pull)

docker pull dockerhub.scbyun.com:5000/apache-php:latest

$ docker pull dockerhub.scbyun.com:5000/apache-php:latest
latest: Pulling from apache-php
2d473b07cdd5: Already exists
1c21b49fc204: Pull complete
ebb71476cd11: Pull complete
7c0c0d52b79c: Pull complete
Digest: sha256:e8b8bfee0020b8ea9b782446c067e9069e238c9dee4dd3870d3777571b4f586b
Status: Downloaded newer image for dockerhub.scbyun.com:5000/apache-php:latest
dockerhub.scbyun.com:5000/apache-php:latest

이미지 업로드(docker push)

docker push dockerhub.scbyun.com:5000/apache-php:latest

$ docker push dockerhub.scbyun.com:5000/apache-php:latest
The push refers to repository [dockerhub.scbyun.com:5000/apache-php]
0d2cbbf556cd: Layer already exists
9e2c1ea8dc21: Layer already exists
174f56854903: Layer already exists
latest: digest: sha256:e8b8bfee0020b8ea9b782446c067e9069e238c9dee4dd3870d3777571b4f586b size: 3265

registry 내부의 repository 정보 조회

curl <ID>:<PASSWORD><REGISTRY URL:PORT>/v2/_catalog

curl https://admin:admin@dockerhub.scbyun.com:5000/v2/_catalog

$ curl https://admin:admin@dockerhub.scbyun.com:5000/v2/_catalog
{"repositories":["apache-php","centos"]}

repository에 대하여 tag 정보 조회

curl <ID>:<PASSWORD><REGISTRY URL:PORT>/v2/<IMAGE NAME>/tags/list

curl https://admin:admin@dockerhub.scbyun.com:5000/v2/apache-php/tags/list

curl https://admin:admin@dockerhub.scbyun.com:5000/v2/apache-php/tags/list
{"name":"apache-php","tags":["0.0.1","latest"]}

매니페스트 정보 확인(content digest 조회)

curl -v  -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \

<ID>:<PASSWORD>@<REGISTRY URL:PORT>/v2/<IMAGE NAME>/manifests/<TAG NAME> 2>&1 \

| grep Docker-Content-Digest | awk '{print ($3)}'

curl 옵션

 -v, --verbose

 -H, --header

curl -v  -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \

https://admin:admin@dockerhub.scbyun.com:5000/v2/apache-php/manifests/0.0.1 2>&1 \

| grep Docker-Content-Digest | awk '{print ($3)}'

$ curl -v -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
> https://admin:admin@dockerhub.scbyun.com:5000/v2/apache-php/manifests/0.0.1 2>&1 \
> | grep Docker-Content-Digest | awk '{print ($3)}'
sha256:f9d01a495f8e1a5d2dc7f04c98be5f05ab2f0390888e511a53d0fdc0bbfde4e3
728x90

매니페스트 다이제스트를 통한 이미지 삭제(이미지 삭제)
curl -v -XDELETE <ID>:<PASSWORD>@<REGISTRY URL:PORT>/v2/<IMAGE NAME>/manifests/<DIGEST>

curl 옵션

 -v, --verbose

 -X, --request COMMAND  Specify request command to use
     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS
     --retry NUM   Retry request NUM times if transient problems occur
     --retry-delay SECONDS When retrying, wait this many seconds between each
     --retry-max-time SECONDS  Retry only within this period

curl -v -XDELETE https://admin:admin@dockerhub.scbyun.com:5000/v2/apache-php/manifests/sha256:e8b8bfee0020b8ea9b782446c067e9069e238c9dee4dd3870d3777571b4f586b

$ curl -v -XDELETE \
https://admin:admin@dockerhub.scbyun.com:5000/v2/apache-php/manifests/sha256:e8b8bfee0020b8ea9b782446c067e9069e238c9dee4dd3870d3777571b4f586b
* About to connect() to dockerhub.scbyun.com port 5000 (#0)
*   Trying 211.239.123.212...
* Connected to dockerhub.scbyun.com (211.239.123.212) port 5000 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
* 	subject: CN=dockerhub.scbyun.com
* 	start date: Mar 17 05:36:28 2022 GMT
* 	expire date: Jun 15 05:36:27 2022 GMT
* 	common name: dockerhub.scbyun.com
* 	issuer: CN=R3,O=Let's Encrypt,C=US
* Server auth using Basic with user 'admin'
> DELETE /v2/apache-php/manifests/sha256:e8b8bfee0020b8ea9b782446c067e9069e238c9dee4dd3870d3777571b4f586b HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.29.0
> Host: dockerhub.scbyun.com:5000
> Accept: */*
>
< HTTP/1.1 202 Accepted
< Docker-Distribution-Api-Version: registry/2.0
< Date: Mon, 28 Mar 2022 09:28:45 GMT
< Content-Length: 0
<
* Connection #0 to host dockerhub.scbyun.com left intact

GC(Garbage Collection)

docker-compose exec registry registry garbage-collect /etc/docker/registry/config.yml

$ docker-compose exec registry registry garbage-collect /etc/docker/registry/config.yml
apache-php
apache-php: marking manifest sha256:c7c959a30104de547d09bdd32ff7d205917c44d100af2651142dc08cf5556ea2
apache-php: marking blob sha256:31723d898881b03d0938162fcb354bb37dbde8d0a908b471e04872a79f960f86
apache-php: marking blob sha256:2d473b07cdd5f0912cd6f1a703352c82b512407db6b05b43f2553732b55df3bc
...
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/29/2994e53ea3cd3d343611a5cc6864afd9ac0a78526e6e23795a06466082dee6a9  go.version=go1.16.15 instance.id=4730ce40-112b-4bbf-8413-17be55568a55 service=registry
blob eligible for deletion: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/a3/a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4  go.version=go1.16.15 instance.id=4730ce40-112b-4bbf-8413-17be55568a55 service=registry
728x90