创建
由公共仓库pull registry镜像
// An highlighted block
[root@localhost docker]# docker pull registry:2.6.2
2.4版本后才支持删除仓库镜像功能
创建私有仓库registry
创建/conf/config.yml文件,内容如下:
version: 0.1
log:
fields:
service: registry
storage:
delete:
enabled: true
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
如果要有删除仓库镜像功能,须增加delete_enabled_true配置
[root@localhost docker]# docker run -d -p 5000:5000 --privileged=true --restart=always --name=registry -v /conf/:/etc/docker/registry/ -v /docker/registry/:/var/lib/registry/ docker.io/registry:2.6.2
上传
生成镜像
docker commit -m "镜像说明" -a "作者" container_id 镜像名称:版本号
修改标签
docker tag 镜像名称:版本号 localhost:5000/镜像名称:版本号
也可以在上一步直接提交到位
上传镜像
docker push localhost:5000/镜像名称:版本号
下载
docker pull localhost:5000/镜像名称:版本号
删除
查看仓库中的镜像
curl -X GET localhost:5000/v2/_catalog
curl -I -X GET <protocol>://<registry_host>/v2/<镜像名>/tags/list
查看需要删除镜像的sha256值
curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X GET localhost:5000/v2/<镜像名>/manifests/<版本号>
删除镜像
curl -I -X DELETE localhost:5000/v2/<><镜像名>/manifests/sha256:<hash值>
删除镜像文件
docker exec <容器名> rm -rf /var/lib/registry/docker/registry/v2/repositories/<镜像名>
docker exec -it <registry_container_id> bin/registry garbage-collect <path_to_registry_config>