feat: support x-context extension to set Docker context in compose.yaml#13694
feat: support x-context extension to set Docker context in compose.yaml#13694ssam18 wants to merge 1 commit intodocker:mainfrom
Conversation
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>
c86db7d to
774cd20
Compare
|
@freeformz @nicksieger - Please approve the workflow and review this PR. |
There was a problem hiding this comment.
@ssam18, can you clarify why this is really needed?
There are already 4 ways to define the context:
--contextflagDOCKER_CONTEXTdefined in a.envfileDOCKER_CONTEXTenv variable in your terminal configdocker context usecommand
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.
|
I agree; I think this should remain an option that's explicitly chosen by the user running compose; a compose-file having |
|
make sense. let me close this PR. |
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.