使用 --format 的 Docker 上下文输出

问题描述

我正在尝试以以下格式列出 docker 上下文 。即

true moby
false aci
false ecs

但是 docker CLI 由于某种原因无法解析上下文类型。

如果我执行 docker context list --format "{{json . }}",我会得到正确的 JSON 输出 -

    {
        "Current": true,"Description": "Current DOCKER_HOST based configuration","DockerEndpoint": "npipe:////./pipe/docker_engine","KubernetesEndpoint": "https://b2kstresst-b2kstresstest-b1fdfb-82f667ef.hcp.eastus.azmk8s.io:443 (default)","ContextType": "moby","Name": "default","StackOrchestrator": "swarm"
    }
    {
        "Current": false,"Description": "azds-aks@eastus","DockerEndpoint": "","KubernetesEndpoint": "","ContextType": "aci","Name": "myacicontext","StackOrchestrator": ""
    }
    {
        "Current": false,"Description": "credentials read from environment","ContextType": "ecs","Name": "myecscontext","StackOrchestrator": ""
    }

如果我执行 docker context list --format "{{json .Current}}",我会得到正确的输出 -

true
false
false

但是执行命令 docker context list --format "{{json .ContextType}}" 会出错 -

Template parsing error: template: :1:25: executing "" at <.ContextType>: can't evaluate field ContextType in type *formatter.clientContextContext

理想情况下,我会执行类似 - docker context list --format "{{json .Current .ContextType}}"

知道如何实现我的目标吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...