gpt4 book ai didi

docker - Ansible中--all如何区分是否剪裁Docker镜像?

转载 作者:行者123 更新时间:2023-12-05 03:59:33 24 4
gpt4 key购买 nike

在 Ansible 剧本中,我们可以请求相当于调用的内容

docker image prune

通过这个:

- name: Clean up Docker images
docker_prune:
images: yes

但是,似乎没有办法请求--all,即修剪所有未在容器中使用的图像。无论如何,默认情况下它不会这样做:

TASK [role : Clean up Docker images] ***
ok: [server] => {
"changed": false,
"images": [],
"images_space_reclaimed": 0
}

显然,images_filters 具有不直接对应于 CLI Docker 选项的选项:

A dictionary of filter values used for selecting images to delete.For example, dangling: true.See the docker documentation for more information on possible filters.

不幸的是,这个选项根本没有记录;删除悬挂图像是默认设置,那么 true 有什么影响呢?

我如何告诉 Ansible 执行与 docker image prune --all 等效的操作?

最佳答案

诀窍是正确猜测 dangling: true 意味着“修剪悬空”。因此,这个任务完成了我们想要的:

- name: Clean up Docker images
docker_prune:
images: yes
images_filters:
dangling: false
TASK [role : Clean up Docker images] ***
ok: [server] => {
"changed": false,
"images": [
{
"Untagged": "docker.io/ruby:alpine"
},
{
"Untagged": "docker.io/ruby@sha256:cbcf3c98e7bd7dfd0a535c91a6c186eed483680cefe0c99ed1ed46d6efbb0e7b"
},
{
"Deleted": "sha256:47c30d96ab20f3004776ff14fce824960f94dd8ba40f689a839d250befa8924e"
},
{
"Deleted": "sha256:1ffdfb9e5dfb8e61532391c9624539dfe6695fa535d8dd375019ae910bc6a263"
},
{
"Deleted": "sha256:59d90740fdbf9dae0a8c7e824cdb25b6636ab7c56d5d90a1ed52cc523123ef7f"
},
{
"Deleted": "sha256:e0b257ffac8a68382fb702142120625ee8c7c579dd22143ac8ee02e0bb23e1eb"
},
{
"Deleted": "sha256:d6fd80a889d96453e9b6b27c475952f0cc90fa6c0d1d922024cb4158362e16eb"
},
{
"Deleted": "sha256:1bfeebd65323b8ddf5bd6a51cc7097b72788bc982e9ab3280d53d3c613adffa7"
}
],
"images_space_reclaimed": 51040409
}

关于docker - Ansible中--all如何区分是否剪裁Docker镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57090073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com