1, 配置本地仓库访问地址
在/etc/docker/daemon.json 中添加如下内容:
"insecure-registries":["xxx.xxx.xxx.xxx:5000"]
然后,重新启动docker
systemctl daemon-relaod
systemctl restart docker
2. 登陆到本地仓库
docker login xxx.xxx.xxx.xxx:5000
3.查看本地仓库
curl xxx.xxx.xxx.xxx:5000/v2/_catalog --user 用户名
输入登陆密码即可,上述方式仅仓库服务添加了用户验证, 如果未添加用户验证,不需要 --user参数
查看具体仓库镜像列表
curl xxx.xxx.xxx.xxx:5000/v2/仓库名/tags/list --user 用户名
4. push 镜像
首先 给进行打上标签,然会docker push 即可
docker tag 当前仓库:镜像版本 xxx.xxx.xxx.xxx:5000/仓库名/镜像名:镜像版本
docker push xxx.xxx.xxx.xxx:5000/仓库名/镜像名:镜像版本
5. pull 镜像
docker pull xxx.xxx.xxx.xxx:5000/仓库名/镜像名:镜像版本
6 删除镜像
首先,确保,registry 启动时,开启了删除功能,默认时不允许删除的, 通过启动时 指定变量开启
-e REGISTRY_STORAGE_DELETE_ENABLED="true"
如果使用.yaml文件配置,则
environment:
REGISTRY_STORAGE_DELETE_ENABLED: "true"
然后,获取该镜像版本的 sha256,地址信息
curl-v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://xxx.xxx.xxx.xxx:5000/v2/仓库名/manifests/版本名 --user 用户名 | grep Docker-Content-Digest | awk '{print ($3)}'
输入用户密码, 输出结果:
HTTP/1.1 200 OK
< Content-Length: 6843
< Content-Type: application/vnd.docker.distribution.manifest.v2+json
< Docker-Content-Digest: sha256:cccfe5a2f926bdf387a84c33d097a56a69b50ba4fe8ae4f8dde881d46a04dba2
< Docker-Distribution-Api-Version: registry/2.0
< Etag: "sha256:cccfe5a2f926bdf387a84c33d097a56a69b50ba4fe8ae4f8dde881d46a04dba2"
< X-Content-Type-Options: nosniff
< Date: Wed, 21 Aug 2019 18:21:51 GMT
然会用 sha256:cccfe5a2f926bdf387a84c33d097a56a69b50ba4fe8ae4f8dde881d46a04dba2 删除进行镜像
curl -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X DELETE http://xxx.xxx.xxx.xxx:5000/v2/仓库名/manifests/sha256:对应的地址信息 --user 用户名
输入用户密码:
Server auth using Basic with user '用户名'
> DELETE /v2/yaspeed/manifests/sha256:cccfe5a2f926bdf387a84c33d097a56a69b50ba4fe8ae4f8dde881d46a04dba2 HTTP/1.1
> Authorization: Basic d3ViYW9saW46d3ViYW9saW4=
> User-Agent: curl/7.29.0
> Host: xxx.xxx.xxx.xxx:5000
> Accept: application/vnd.docker.distribution.manifest.v2+json
>
< HTTP/1.1 202 Accepted
< Docker-Distribution-Api-Version: registry/2.0
< X-Content-Type-Options: nosniff
< Date: Wed, 21 Aug 2019 18:23:52 GMT
< Content-Length: 0
此时的删除,仅仅删除了元数据,还需要通过 回收垃圾回收,才能真正删除磁盘上的镜像: 注意该步骤在启动仓库的 设备上执行
docker exec -it 仓库容器名 /bin/registry garbage-collect /etc/docker/registry/config.yml
blob eligible for deletion: sha256:31c5fcb7cbbef2ed109332f7383afaf85071cc8074849fb3e1f3d285edbeb320
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/31/31c5fcb7cbbef2ed109332f7383afaf85071cc8074849fb3e1f3d285edbeb320 go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:67fb292896fd75ed7ac6372608e733f708eda066741cebe3fa38e81c1155d782
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/67/67fb292896fd75ed7ac6372608e733f708eda066741cebe3fa38e81c1155d782 go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:3d76e4442589c401fafc449d49e8152bc56f204ac6e918233ebf2fded9cabc44
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/3d/3d76e4442589c401fafc449d49e8152bc56f204ac6e918233ebf2fded9cabc44 go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:51f2ce3fafc16e72aabdc87c27b8708b92811ca3eb6afdde4d007880eb655f5b
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/51/51f2ce3fafc16e72aabdc87c27b8708b92811ca3eb6afdde4d007880eb655f5b go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:57013ca4260251e5a93acd8b7bf878e8f60a10a7d8b1870a29c9b42bafa234d6
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/57/57013ca4260251e5a93acd8b7bf878e8f60a10a7d8b1870a29c9b42bafa234d6 go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:6bf6e57f750354947c6bcf100aa6ac2763cfa9a010be073eeee4715180cabc8d
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/6b/6bf6e57f750354947c6bcf100aa6ac2763cfa9a010be073eeee4715180cabc8d go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:7fd92b7fea8739e944b82e09ac2c6bf4542f659985b58fa5b8f30973d40804ce
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/7f/7fd92b7fea8739e944b82e09ac2c6bf4542f659985b58fa5b8f30973d40804ce go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:aaa9a2ecd3cafb1b57be4b70b1543ebf3da0159f57b4abcce6c19c25a4238f58
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/aa/aaa9a2ecd3cafb1b57be4b70b1543ebf3da0159f57b4abcce6c19c25a4238f58 go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:ab0838c577485941002e9019e262c36f6f33f2fbaafc3a74099b345c3f54b4dc
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/ab/ab0838c577485941002e9019e262c36f6f33f2fbaafc3a74099b345c3f54b4dc go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
blob eligible for deletion: sha256:1760d9e23cb5f0ef17bfa45e2d4ef3a6e357958b48b21a3072aa6171b5486d27
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/17/1760d9e23cb5f0ef17bfa45e2d4ef3a6e357958b48b21a3072aa6171b5486d27 go.version=go1.11.2 instance.id=937b9466-0972-455a-ad90-12ad49994c43 service=registry
等待删除完成即可