我正在尝试以 <current, type> 的格式列出 docker 上下文。IE
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",
"DockerEndpoint": "",
"KubernetesEndpoint": "",
"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}}"
知道如何实现我想要做的事情吗?