Skip to content

feat: support x-context extension to set Docker context in compose.yaml#13694

Closed
ssam18 wants to merge 1 commit intodocker:mainfrom
ssam18:feat/x-context-compose-yaml
Closed

feat: support x-context extension to set Docker context in compose.yaml#13694
ssam18 wants to merge 1 commit intodocker:mainfrom
ssam18:feat/x-context-compose-yaml

Conversation

@ssam18
Copy link
Copy Markdown
Contributor

@ssam18 ssam18 commented Apr 1, 2026

This adds support for an x-context top-level extension in compose.yaml that lets users pin a named Docker context for all compose operations. It removes the need to pass --context on every invocation when working with non-default contexts like rootless or remote SSH endpoints. The implementation detects the extension after loading the project and reinitializes the Docker CLI for the specified context before dispatching to the backend.

@ssam18 ssam18 requested a review from a team as a code owner April 1, 2026 01:22
@ssam18 ssam18 requested review from glours and ndeloof April 1, 2026 01:22
Allow users to specify a Docker context at the compose project level via an x-context extension field. When set, all compose operations use the
specified context instead of the CLI default, without needing --context on every invocation. Fix for the bug docker#13501

Signed-off-by: Samaresh Kumar Singh <ssam3003@gmail.com>
@ssam18 ssam18 force-pushed the feat/x-context-compose-yaml branch from c86db7d to 774cd20 Compare April 1, 2026 01:25
@ssam18
Copy link
Copy Markdown
Contributor Author

ssam18 commented Apr 2, 2026

@freeformz @nicksieger - Please approve the workflow and review this PR.

Copy link
Copy Markdown
Contributor

@glours glours left a comment

Choose a reason for hiding this comment

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

@ssam18, can you clarify why this is really needed?

There are already 4 ways to define the context:

  • --context flag
  • DOCKER_CONTEXT defined in a .env file
  • DOCKER_CONTEXT env variable in your terminal config
  • docker context use command

Three of these already address the need to avoid passing --context explicitly.

In my opinion, introducing this kind of attribute in Compose would not add much value, and would instead create more ambiguity around Compose behavior.

For example, what happens if a Compose file sets x-context: contextA, while the user has DOCKER_CONTEXT=contextB in their .env file?

Or even worse, imagine a Compose file with x-context: desktop-linux, while the user has explicitly selected docker context use my_rootless_context.

I’m honestly strongly against adding this. The existing mechanisms already cover this use case, and introducing another way to define the context would make Compose behavior much more confusing and harder to reason about.

@thaJeztah
Copy link
Copy Markdown
Member

I agree; I think this should remain an option that's explicitly chosen by the user running compose; a compose-file having x-context: my-production-machine means that a user may accidentally make changes to the production environment (but thinking they're using their "dev" environment).

@ssam18
Copy link
Copy Markdown
Contributor Author

ssam18 commented Apr 2, 2026

make sense. let me close this PR.

@ssam18 ssam18 closed this Apr 2, 2026
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.

3 participants