首页 > 解决方案 > docker ps 过滤标签不存在或不等于一个值 [Go Template]

问题描述

我想选择没有键或值不等于某物的容器。我有了从这里使用docker inspect这里检查密钥存在的想法

但这并不完全适合我的情况。我试过了

跑步

docker container inspect -f '{{if (ne (index $.Config.Labels "agent") "delete") }}{{.Id}} {{ end }}' $(docker ps -q)

我有

error calling ne: invalid type for comparison

跑步

docker container inspect -f '{{with .Config.Labels.agent}} {{if (ne . "delete") }}{{$.Id}}{{end}} {{else}} {{$.Id}} {{end}}' $(docker ps -aq)

我有

map has no entry for key "agent"

现在我很困惑。如何实现:带有标签agent!="delete"agent键的过滤容器未分配值?

标签: dockergo-templates

解决方案


推荐阅读