close
Skip to content

fix(context): use default config dir when config.json is missing#3404

Open
immanuwell wants to merge 1 commit into
docker:mainfrom
immanuwell:fix/context-default-config-dir
Open

fix(context): use default config dir when config.json is missing#3404
immanuwell wants to merge 1 commit into
docker:mainfrom
immanuwell:fix/context-default-config-dir

Conversation

@immanuwell
Copy link
Copy Markdown

Fixes #2622.

This fixes context lookup when Docker config exists only as the default dir, with no config.json yet.
Right now docker-py falls back to ./contexts, which is kinda wrong, and set_current_context() blows up instead of creating config.json.

Repro:

  1. Make sure ~/.docker/config.json does not exist.
  2. Create a context with Docker CLI, so ~/.docker/contexts/... exists.
  3. Run:
from docker.context import ContextAPI
print(ContextAPI.contexts())
ContextAPI.set_current_context("my-context")

Before:

  • ContextAPI.contexts() only finds default
  • ContextAPI.set_current_context() fails
  • creating a context can write ./contexts in the cwd, not great

After:

  • context paths resolve under the default Docker config dir
  • set_current_context() creates config.json if needed

Checks:

  • uv run --with pytest pytest tests/unit/context_test.py tests/unit/utils_config_test.py -q
  • broader unit checks around this area pass too, the only extra failures I hit on current main were pre-existing timezone-sensitive tests

Signed-off-by: immanuwell <pchpr.00@list.ru>
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.

Cannot find contexts if Docker config file is not present

2 participants