You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何列出由Testcontainers启动的所有Docker容器?

过滤Docker容器仅显示Testcontainers启动的实例

Testcontainers在启动容器时会自动添加特定标识,你可以通过以下几种方式过滤docker ps的输出:

方法一:通过专属标签过滤

Testcontainers会给所有它启动的容器打上org.testcontainers=true标签,直接用这个标签筛选即可:

docker ps --filter "label=org.testcontainers=true"

如果需要查看包括已停止在内的所有Testcontainers容器,加上-a参数:

docker ps -a --filter "label=org.testcontainers=true"

方法二:通过容器名称特征过滤

Testcontainers启动的容器名称通常包含testcontainers关键词,或是以tc-作为前缀(不同语言的Testcontainers实现可能略有差异),也可以用名称匹配:

docker ps --filter "name=testcontainers"

或者精准匹配前缀:

docker ps --filter "name=tc-"

自定义输出格式(可选)

如果想简化输出内容,比如只展示容器ID、名称和状态,可以指定输出格式:

docker ps --filter "label=org.testcontainers=true" --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"

内容的提问来源于stack exchange,提问作者Per Lundberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 13:40:55