如何搜索与“ docker ps --filter”结果不匹配的容器? [英] How to search for containers that don't match the result of "docker ps --filter"?

查看:438
本文介绍了如何搜索与“ docker ps --filter”结果不匹配的容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过名称找到一个Docker容器: docker ps --filter ='name = mvn_repo'。有没有一种方法(不求助于bash / awk / grep等)来否定此过滤器并列出除具有给定名称的容器以外的所有容器?

I can find a docker container by name: docker ps --filter='name=mvn_repo'. Is there a way (without resorting to bash/awk/grep etc.) to negate this filter and list all containers except the one with the given name?

推荐答案

您可以使用 docker inspect 进行此操作,我创建了一个具有--name = test111的容器,它显示为/ test111,因此如果我这样做

You can use docker inspect to do this, I created a container with --name=test111, it appears as /test111, so if I do

docker inspect -f'{{if ne test111 .Name}} {{。Name}} {{end}}'$(docker ps -q)
/ test111
/ sezs
/ jolly_galileo
/ distracted_mestorf
/ cranky_nobel
/ goofy_turing
/ modest_brown
/ serene_wright
/ fervent_lalande

但如果我使用/进行过滤,则它变成

but if I do a filter with the /, so it becames

docker inspect -f'{{if ne / test111 .Name} } {{。Name}} {{end}}'$(docker ps -q)
/ sezs
/ jolly_galileo
/ distracted_mestorf
/ cranky_nobel
/ goofy_turing
/ modest_brown
/ serene_wright
/ fervent_lalande

我不明白。

对Adrian Mouat的关于docker inspect的参考文章表示敬意

Kudos to Adrian Mouat for his reference post on docker inspect

http://container-solutions.com/docker-inspect-template-magic/

如他所说

(不幸的是,Docker为每个容器打印换行符,无论是否与if匹配)。
如果我空白行,则格式会丢失。

"(Unfortunately Docker prints a new-line for each container, whether it matches the if or not)." If I put a blank line the formatting is lost.

这篇关于如何搜索与“ docker ps --filter”结果不匹配的容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆