Oracle 系统管理 - Linux 系统 - Backtrack 5 - 安全 - Juniper 技术 - Cisco 技术 - 思科模拟器 - Cisco 认证 - Cisco ios 下载

您现在的位置是:Docker > Docker > Docker 镜像清理和删除

Docker 镜像清理和删除

时间:2018-07-13 10:37  来源:未知  阅读次数: 复制分享 我要评论

  • 客户端

删除所有

docker kill $(docker ps -aq)
docker rm $(docker ps -aq)
docker rmi $(docker images -q)
docker volume rm $(docker volume ls -q)

 

不删除现有运行镜像

docker rm $(docker ps -aq)
docker rmi $(docker images -q)
docker volume rm $(docker volume ls -q)

 

  • Registry清理空间

配置开启删除功能 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
复制代码

 

获取镜像的digest

curl --cacert /etc/docker/certs.d/192.168.0.34\:5000/ca.crt -H "Accept:application/vnd.docker.distribution.manifest.v2+json" https://192.168.0.34:5000/v2/messer/manifests/1.0

REST API

/v2/<镜像名称>/manifests/<tag>

返回信息

复制代码
{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
   "config": {
      "mediaType": "application/octet-stream",
      "size": 4191,
      "digest": "sha256:c8043677c5d750e0904298c29825d1da8389a1ea2e2564e076ed54a023ece056"
   },
   "layers": [
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 51363125,
         "digest": "sha256:75a822cd7888e394c49828b951061402d31745f596b1f502758570f2d0ee79e2"
      },
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 20179224,
         "digest": "sha256:0aefb9dc4a57d3de6a9cfa2e87e4502dfa8ce3876264bb20783b1610f8e44806"
      },
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 193,
         "digest": "sha256:046e44ee6057f1264d00b0c54adcff2f2c44d30a29b50dfef928776f7aa45cc8"
      },
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 596,
         "digest": "sha256:614a7b3525a1442775b9d1b52413024dc750b6a9169fcae8d4ef9cf98bda7f0f"
      },
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 1083978,
         "digest": "sha256:5fe57df972ae5e10f02783cb372841e6feab67a296e2abc16f9a868e4322c33d"
      }
   ]
}
复制代码

 

我们要的就是"digest": "sha256:c8043677c5d750e0904298c29825d1da8389a1ea2e2564e076ed54a023ece056"这个值

 

通过delete删除镜像

curl --cacert /etc/docker/certs.d/192.168.0.34\:5000/ca.crt -X DELETE https://192.168.0.34:5000/v2/messer/manifests/sha256:c8043677c5d750e0904298c29825d1da8389a1ea2e2564e076ed54a023ece056

 

返回不是404 就是删除了

 

回收空间

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

 

复制代码
root@83d6f5acc9f5:/# /bin/registry garbage-collect /etc/docker/registry/config.yml
INFO[0013] Deleting blob: /docker/registry/v2/blobs/sha256/c0/c0c9ad6136b5e7b142c48c7167eede3d15af54c538f7f3177c50693006cca242  go.version=go1.6.2 instance.id=73c88c92-c196-413e-9cdf-413760de2a62
INFO[0013] Deleting blob: /docker/registry/v2/blobs/sha256/0c/0c1f3512513001c7e37c0dff11064a5c76ad9098507ee74189d6a810742173d7  go.version=go1.6.2 instance.id=73c88c92-c196-413e-9cdf-413760de2a62
复制代码
相关资讯