Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

enhancement: show when context is overridden by "DOCKER_HOST" or other options

未关闭
#6,151 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
docker, go
领域
cli

调研方向

先阅读 cli/command/cli.go 以及 cli/command/context/list.go 和 cli/command/context/use.go 中的警告逻辑。比较 docker version 和 docker info 当前如何报告 Context,然后定义被覆盖的 Context 和活动 Host 的输出与格式化行为。当设计解决了未决方案,同时不破坏格式化输出或脚本预期时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

kind/feature status/1-design-review
Description

The Docker CLI defaults to using a local daemon through a unix-socket (Linux, macOS) or named pipe (Windows), but it can be configured to use a different connection, which can be a remote machine.

There's various ways to configure the CLI; (also see DockerCli.CurrentContext);

  • DOCKER_HOST (takes precedence over context)
  • --host / -H (configures the connection to use)
  • DOCKER_CONTEXT (configure the context, which is used to configure the connection)
  • --context (configure the context, which is used to configure the connection)
  • currentContext field in ~/.docker/config.json (configures the default context to configure the connection)
  • In rootless-mode, other env-vars may be involved for the default socket path.

Some of these options may not be very visible; we have some warnings when performing docker context operations to inform the user that DOCKER_HOST is set (and overrides the selected context);
https://github.com/docker/cli/blob/1d768f8983f90abaf7065c76102312eb2ffc42a4/cli/command/context/list.go#L110-L113
https://github.com/docker/cli/blob/1d768f8983f90abaf7065c76102312eb2ffc42a4/cli/command/context/use.go#L52-L55

However, other places may not show this information. Most notably docker version and docker info;

Current context (in the CLI's config) is desktop-linux;

cat ~/.docker/config.json | jq .currentContext
"desktop-linux"

However, docker version shows that the default context is used;

docker version
Client:
 Version:           28.3.0-rc.1
 API version:       1.42 (downgraded from 1.51)
 Go version:        go1.24.4
 Git commit:        f53bb88
 Built:             Fri Jun 13 18:25:06 2025
 OS/Arch:           darwin/arm64
 Context:           default

And docker info does the same;

docker info | head -n 5
Client:
 Version:    28.3.0-rc.1
 Context:    default
 Debug Mode: false
 Plugins:

In the above situation, the reason was that DOCKER_HOST was set in the current shell;

env | grep DOCKER
DOCKER_HOST=ssh://swarm-test-01/var/run/docker.sock

Improvement: make active connection more visible

⚠️ This is just a draft; detailed design still needed

1. Include "Docker Host" in docker version and docker info

We can include the active host in output of docker version and docker info;

docker version
Client:
 Version:           28.3.0-rc.1
 API version:       1.42 (downgraded from 1.51)
 Go version:        go1.24.4
 Git commit:        f53bb88
 Built:             Fri Jun 13 18:25:06 2025
 OS/Arch:           darwin/arm64
 Context:           default
 Docker Host:       ssh://swarm-test-01/var/run/docker.sock
docker info | head -n 5
Client:
 Version:     28.3.0-rc.1
 Context:     default
 Docker Host: ssh://swarm-test-01/var/run/docker.sock
 Debug Mode:  false
  • ☝️ alternatively, we could include this in the Server section, however, the Server itself may be serving the API on multiple "hosts" (e.g. both on a socket AND through tcp); https://github.com/moby/moby/pull/43459
2. Show what determined the active context

We can show "why" the given context is used, e.g.;

 Context:           default (context disabled because DOCKER_HOST is set)
 Context:           desktop-linux (from DOCKER_CONTEXT)
 Context:           desktop-linux (from "~/.docker/config.json`)

⚠️ the above output may be used by users in scripting (docker version | grep 'Context:');

  • Generally, users should use docker context show for this, but it may be a breaking change
  • When formatting, we should make this a separate part of the template so that docker version --format '{{.Client.Context}}' only shows the context name (same for `docker info --format``)
3. Show what determined the active "host" connection

Similar to the above; show where the connection string came from;

 Docker Host:       ssh://swarm-test-01/var/run/docker.sock (from DOCKER_HOST)

❓ should we also show if this comes from the active context? (when not overridden by DOCKER_HOST)? Or is that just "noise"?

 Docker Host:       ssh://swarm-test-01/var/run/docker.sock (from "desktop-linux" context)

or

 Docker Host:       ssh://swarm-test-01/var/run/docker.sock (from current context)
主要语言
Go
星标
6.1k
派生
2.2k
平均合并
1 天 10 小时
30 天内合并 PR
47

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

docker/cli 的其他 Issue

查看 docker/cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。