Skip to content

fix(build): keep a named context's buildx builder when shelling out to bake - #14434

Open
htoyoda18 wants to merge 2 commits into
docker:mainfrom
htoyoda18:fix/bake-named-context-builder
Open

htoyoda18 wants to merge 2 commits into
docker:mainfrom
htoyoda18:fix/bake-named-context-builder

Conversation

@htoyoda18

@htoyoda18 htoyoda18 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

With a named Docker context (e.g. Docker Desktop's desktop-linux), docker compose build ignored the buildx builder selected for that context and reset the selection, because Compose always passed DOCKER_HOST to the bake process and that makes the docker CLI resolve the default context. This PR passes only DOCKER_CONTEXT for a named context, and keeps passing DOCKER_HOST and TLS material for the default context, which is also the one in use with -H or DOCKER_HOST.

Related issue

Fixes #14433

Changes made

  • pkg/compose/shellout.go: propagateDockerEndpoint returns only DOCKER_CONTEXT (and USER_AGENT) when the current context is not command.DefaultContextName. A named context already carries its endpoint and TLS material, and the child CLI plugin resolves it by name, together with per-context state such as the selected buildx builder. For the default context nothing changes.
  • pkg/compose/shellout_test.go (new): table-driven TestPropagateDockerEndpoint covering a named context, a named TLS context, the default context, and the default context with TLS. Before the fix, both named cases failed because DOCKER_HOST was set.

Testing done

  • Unit tests pass: make test
  • E2E tests pass: make e2e-compose or make e2e-compose-standalone
  • Linting passes: make lint
  • Code formatted: make fmt
  • Manually tested (describe):

AI tool used (if applicable)

AI Tool:

Additional context

This area has changed several times, so the new test pins all the cases the earlier fixes were about.

(not mandatory) A picture of a cute animal, if possible in relation to what you did

image

…o bake

Signed-off-by: hiroto.toyoda <hiroto.toyoda@dena.com>
@htoyoda18
htoyoda18 marked this pull request as ready for review November 1, 2026 15:07
@htoyoda18
htoyoda18 requested review from a team as code owners November 1, 2026 15:07
@htoyoda18
htoyoda18 requested review from glours and ndeloof November 1, 2026 15:07
ndeloof
ndeloof previously approved these changes Nov 2, 2026
@htoyoda18

Copy link
Copy Markdown
Contributor Author

@ndeloof Thanks for the review! Could you approve the CI workflows when you have a moment?

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve an explicit named context when DOCKER_HOST is inherited

doBuildBake builds cmd.Env from os.Environ() and then appends this function's values. With DOCKER_HOST=tcp://old:2375 docker --context desktop-linux compose build, the parent CLI selects desktop-linux because the explicit --context flag wins. This branch only appends DOCKER_CONTEXT=desktop-linux; it leaves the inherited DOCKER_HOST in cmd.Env. The child buildx CLI has no --context flag, and Docker CLI's resolveContextName checks DOCKER_HOST before DOCKER_CONTEXT, so it falls back to default and builds against the wrong daemon. Please remove inherited DOCKER_HOST and TLS overrides from the child environment for a named context, and test the combined environment passed to buildx with both variables set.

Signed-off-by: hiroto.toyoda <hiroto.toyoda@dena.com>
@htoyoda18

Copy link
Copy Markdown
Contributor Author

@agammann
Good catch, thanks! For a named context, the child now gets DOCKER_HOST and the TLS variables blanked, so it resolves the context like the parent does. The test now checks the environment the child actually receives, with those variables inherited.

@htoyoda18
htoyoda18 requested a review from ndeloof November 4, 2026 07:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] docker compose build ignores the buildx builder selected for a named context, and resets that selection

3 participants