Skip to content

cli/config: error when the config directory is not a directory - #7235

Open
4RH1T3CT0R7 wants to merge 1 commit into
docker:masterfrom
4RH1T3CT0R7:fix-config-dir-not-a-directory
Open

cli/config: error when the config directory is not a directory#7235
4RH1T3CT0R7 wants to merge 1 commit into
docker:masterfrom
4RH1T3CT0R7:fix-config-dir-not-a-directory

Conversation

@4RH1T3CT0R7

@4RH1T3CT0R7 4RH1T3CT0R7 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Pointing DOCKER_CONFIG (or --config) at the config file instead of its directory breaks differently on each platform: on unix it fails with open /tmp/xxx/config.json/config.json: not a directory, naming a path that can't exist, and on Windows it's silently ignored, so docker logout reports success without writing anything.

When opening the config fails, load() now stats the config directory and warns if it isn't one. The check has to come before the os.IsNotExist branch, since on Windows this case is an is-not-exist error, and the underlying error isn't wrapped so errors.Is callers can still tell it apart from "no config file present".

It warns rather than failing hard: failing hard would mean changing LoadDefaultConfigFile's signature or moving the check into cli/command/cli.go. Happy to do that in a follow-up if you'd rather.

Fixes #5037.

Report a clear warning when DOCKER_CONFIG or --config points to a file instead of a directory.

Setting DOCKER_CONFIG (or --config) to the config file itself instead of
the directory containing it is a common mistake, and one the CLI handled
inconsistently:

- on Windows, opening "<config.json>/config.json" fails with a "not
  exist" error, which load() treats as "no config file present", so the
  misconfiguration was silently ignored, and every command ran with
  default configuration. "docker logout" then reported success without
  writing anything, because there are no credentials to erase in a
  defaulted config, and it returns before saving. "docker login" did
  fail, but only once it tried to write, with "mkdir <path>\config.json:
  The system cannot find the path specified".
- on unix, the same open fails with ENOTDIR, so the CLI did report an
  error, but it named a path that cannot exist
  ("open /tmp/x/config.json/config.json: not a directory").

Stat the config directory when opening the config file fails, and report
the actual problem. The check has to precede the os.IsNotExist branch,
because on Windows this case *is* an "is not exist" error. The write
path is unchanged, and still fails with the mkdir error above.

This adds one stat to the paths where opening the config file already
failed, which includes the common case of a fresh install that has no
~/.docker yet.

Signed-off-by: Artem Lytkin <iprintercanon@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@4RH1T3CT0R7

Copy link
Copy Markdown
Contributor Author

The two failing checks are the milestone and impact/ label, which I can't set from a fork. Happy to drop the changelog block if you'd rather not have one.

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.

Error messages are wildly inaccurate when DOCKER_CONFIG is set to a file instead of a directory

2 participants