docker registry私有仓库搭建
获取registry镜像
官网地址: https://hub.docker.com/_/registry/
官网文档: https://docs.docker.com/registry/deploying/#start-the-registry-automatically
快速运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| $ docker run -d -p 5000:5000 --restart always --name registry registry:2
cat /etc/docker/daemon.json << EOF { "insecure-registries":["localhost:5000"] } EOF
systemctl daemon-reload systemctl restart docker
$ docker pull nginx $ docker tag ubuntu localhost:5000/nginx:test $ docker push localhost:5000/nginx:test
$ docker pull localhost:5000/nginx:test
$ docker container stop registry && docker container rm -v registry
|
启动配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| docker run --entrypoint htpasswd registry:2 -Bbn admin admin >>/home/xinchen/registry/auth/htpasswd
docker run -d \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \ -e REGISTRY_HTTP_ADDR=0.0.0.0:5001 \ -v /mnt/registry:/var/lib/registry \ -v /home/xinchen/registry/auth:/auth \ -p 5000:5001 \ --name registry-test \ registry:2
docker login localhost:5000
|
API
官网: https://docs.docker.com/registry/spec/api/#detail
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| curl -XGET 127.0.0.1:5000/v2/
curl -XGET 127.0.0.1:5000/v2/_catalog
curl -XGET 127.0.0.1:5000/v2/nginx/tags/list
curl -I http://localhost:5000/v2/nginx/manifests/test
curl -XGET http://localhost:5000/v2/nginx/manifests/test
|
PULL/PUSH镜像过程
PULL镜像过程
image
是由JSON manifest
(JSON清单) 和individual layer files
(单个图层文件),pull image
的过程围绕检索这两个组件
digest
概要是镜像各个层的唯一标识。虽然算法允许使用任意算法,但是为了兼容性应该使用sha256。
例:sha256:6c3c624b58dbbcd3c0dd82b4c53f04194d1247c6eebdaab7c610cf7d66709b3b
field |
description |
name |
The name of the image. |
tag |
The tag for this version of the image. |
fsLayers |
A list of layer descriptors (including digest) |
signature |
A JWS used to verify the manifest content |
当获取清单之后,客户端需要验证签名signature
,以确保名称和层是有效的。
确认后,客户端可以使用digest
去下载各个层,在v2API
中,层存储在blobs
中以digest
作为键值。
1 2
| curl -XGET http://localhost:5000/v2/nginx/blobs/sha256:f17d81b4b692f7e0d6c1176c86b81d9f2cb5ac5349703adca51c61debcfe413c
|
PUSH镜像过程
推镜像和拉取镜像过程相反,先推各个层到registry仓库,然后上传manifest
(清单)。
1 2 3
|
curl -I http://localhost:5000/v2/nginx/blobs/sha256:f17d81b4b692f7e0d6c1176c86b81d9f2cb5ac5349703adca51c61debcfe413c
|