gpt4 book ai didi

docker - 多个docker过滤器选项是否执行本地AND或OR操作?

转载 作者:行者123 更新时间:2023-12-02 18:21:05 25 4
gpt4 key购买 nike

我正在尝试使用多个过滤器执行prune操作。这在docs here中涉及:

The filtering flag (--filter) format is of “key=value”. If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz")



文档未提及是否使用多个过滤器,例如使用逻辑 ANDOR操作将它们组合在一起。

我希望它是一个 AND操作,以便可以执行以下操作:
docker image prune --all --force --filter="label=com.company.product=myproduct" \
--filter="label!=com.company.project=proj2"

具有以下标签的Dockerfile不会被修剪:
LABEL com.company.product="myproduct" com.company.project="proj2"

这可能吗?

最佳答案

简短答案

这是一个AND

测试...

3 Dockerfiles:

FROM alpine
LABEL apples="fruit"

FROM alpine
LABEL oranges="fruit"

FROM alpine
LABEL apples="fruit" oranges="fruit"

3 images:
$ docker image ls 
REPOSITORY TAG IMAGE ID CREATED SIZE
both latest e9e48f31222f 11 seconds ago 4.41MB
oranges latest f384e4db9974 33 seconds ago 4.41MB
apples latest 06fa8c565ec1 51 seconds ago 4.41MB
--filter测试如下*:
$ docker image ls --filter label=apples=fruit
REPOSITORY TAG IMAGE ID CREATED SIZE
both latest e9e48f31222f 34 seconds ago 4.41MB
apples latest 06fa8c565ec1 About a minute ago 4.41MB

$ docker image ls --filter label=oranges=fruit
REPOSITORY TAG IMAGE ID CREATED SIZE
both latest e9e48f31222f 44 seconds ago 4.41MB
oranges latest f384e4db9974 About a minute ago 4.41MB

$ docker image ls --filter label=apples=fruit --filter label=oranges=fruit
REPOSITORY TAG IMAGE ID CREATED SIZE
both latest e9e48f31222f About a minute ago 4.41MB

修剪

名为 both的图像(具有两个标签)被删除:
$ docker image prune -a --filter label=apples=fruit --filter label=oranges=fruit
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: both:latest
deleted: sha256:e9e48f31222f04dd54cffb4688367338d8e061ef3b1471768c1ef6a7045007ab

*注意: docker image ls不适用于 docs中的 负过滤( !=):

Predicting what will be removed

If you are using positive filtering (testing for the existence of a label or that a label has a specific value), you can use docker image ls with the same filtering syntax to see which images match your filter.

However, if you are using negative filtering (testing for the absence of a label or that a label does not have a specific value), this type of filter does not work with docker image ls so you cannot easily predict which images will be removed. In addition, the confirmation prompt for docker image prune always warns that all dangling images will be removed, even if you are using --filter.

关于docker - 多个docker过滤器选项是否执行本地AND或OR操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53066701/

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