美文网首页
docker私有仓库registry的查,删镜像操作

docker私有仓库registry的查,删镜像操作

作者: Odven | 来源:发表于2020-04-07 14:47 被阅读0次

    创建registry私有仓库

    docker container  run -itd --restart=always --name docker-registry -p 5000:5000 -v /data/docker-registry/config/config.yml:/etc/docker/registry/config.yml -v /data/docker-registry/registry/:/var/lib/registry registry:latest
    

    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
    

    **********************************************************

    1. 查询registry的镜像

    curl -s -XGET <protocol>://<私有仓库地址>/v2/_catalog
    如:
    curl -s -XGET http://192.168.192.250:5000/v2/_catalog
    {"repositories":["centos7"]}
    

    2. 查询具体镜像的tag

    curl -s -XGET <protocol>://<私有仓库地址>/v2/<image_name>/tags/list
     如:
    curl -s -XGET http://192.168.192.250:5000/v2/centos7/tags/list
    {"name":"centos7","tags":["latest"]}
    

    3. 查询具体镜像的digest,用于后面的删除镜像清单

    curl  -I -s -XGET --header "Accept: application/vnd.docker.distribution.manifest.v2+json" <protocol>://<私有仓库地址>/v2/<image_name>/manifests/<tag>
    如:
    curl  -I -s -XGET --header "Accept: application/vnd.docker.distribution.manifest.v2+json" http://192.168.192.250:5000/v2/centos7/manifests/latest  | awk '/Docker-Content-Digest/{print $NF}'
    sha256:285bc3161133ec01d8ca8680cd746eecbfdbc1faa6313bd863151c4b26d7e5a5
    

    4. 根据具体镜像的digest删除清单

    curl  -I -s -XDELETE --header "Accept: application/vnd.docker.distribution.manifest.v2+json" <protocol>://<私有仓库地址>/v2/<image_name>/manifests/<image_digest>
    如:
    curl  -I -s -XDELETE --header "Accept: application/vnd.docker.distribution.manifest.v2+json" http://192.168.192.250:5000/v2/centos7/manifests/sha256:285bc3161133ec01d8ca8680cd746eecbfdbc1faa6313bd863151c4b26d7e5a5
    

    5. 删除文件系统内的镜像文件

    docker container exec docker-registry /bin/registry garbage-collect /etc/docker/registry/config.yml
    

    相关文章

      网友评论

          本文标题:docker私有仓库registry的查,删镜像操作

          本文链接:https://www.haomeiwen.com/subject/notnphtx.html