docker 停靠程序ps --格式“{{.名称}} {{.状态}}”不起作用

cigdeys3  于 2023-03-07  发布在  Docker
关注(0)|答案(1)|浏览(123)

执行的命令:

docker ps --format "{{.Names}} {{.State}}"

抛出错误:

Template parsing error: template: :1:13: executing "" at <.State>: can't evaluate field State in type *formatter.containerContext

Docker版本使用:Docker版本18.09.7,构建版本2d0083d
我期望容器名称和状态(例如;"已创建"、"正在运行"、"已退出")。
我推荐了这个医生,但没用。

qv7cva1a

qv7cva1a1#

.State占位符was added in July 2019Docker 20.10起可用(请参见20.10.0客户端发行说明)。
安装了旧版本后,我得到了相同的输出:

docker --version
Docker version 19.03.8, build afacb8b
docker ps --format "{{.Names}} {{.State}}"
Template parsing error: template: :1:13: executing "" at <.State>: can't evaluate field State in type *formatter.containerContext

JSON格式显示没有State键:

docker ps --format "{{json .}}"
{"Command":"...","CreatedAt":"...","ID":"...","Image":"...","Labels":"...","LocalVolumes":"...","Mounts":"...","Names":"...","Networks":"...","Ports":"...","RunningFor":"...","Size":"...","Status":"..."}

相关问题