DOCKER_CONFIG env var is parsed inconsistently and incorrectly in fromDockerConfig / fromDockerContext

Open Beginner friendly
#76 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, typescript
Domain
devops

Research direction

Start in lib/docker-client.ts at fromDockerConfig and fromDockerContext, then trace how each entry point resolves DOCKER_CONFIG and the default home-directory path. Done means both entry points use the Docker config directory consistently, including config.json and contexts paths, while preserving behavior when DOCKER_CONFIG is unset.

Written by the indexing model from the issue text.

Description

DOCKER_CONFIG is the path to Docker's config directory (default ~/.docker), but docker-client.ts interprets it two different ways, and neither matches that.

1. fromDockerConfig treats it as the path to config.json

https://github.com/docker/node-sdk/blob/a4d38673441c1463870fe3ba7c77c067f0bf1e46/lib/docker-client.ts#L267-L270

const configPath =
    process.env.DOCKER_CONFIG ||
    join(homedir(), '.docker', 'config.json');

With DOCKER_CONFIG=/etc/docker-config, this does readFile('/etc/docker-config', 'utf8') on a directory, which fails with EISDIR. That is not ENOENT, so the "config file doesn't exist, use default" branch below doesn't catch it either — the error propagates and fromDockerConfig() throws instead of connecting. It should be join(configDir, 'config.json').

2. fromDockerContext treats it as a directory, then appends .docker

https://github.com/docker/node-sdk/blob/a4d38673441c1463870fe3ba7c77c067f0bf1e46/lib/docker-client.ts#L180-L182

const configDir = process.env.DOCKER_CONFIG || homedir();
const contextsDir = join(configDir, '.docker', 'contexts', 'meta');
const tlsDir = join(configDir, '.docker', 'contexts', 'tls');

The .docker component is only correct for the homedir() fallback. With DOCKER_CONFIG=/etc/docker-config this looks in /etc/docker-config/.docker/contexts/meta rather than /etc/docker-config/contexts/meta, so context lookup fails with Docker contexts directory not found.

The two readings are mutually inconsistent — at most one could be right for a given value of the variable.

Expected

Both should resolve the config directory the same way, e.g.

const configDir = process.env.DOCKER_CONFIG || join(homedir(), '.docker');
// config.json  -> join(configDir, 'config.json')
// contexts     -> join(configDir, 'contexts', 'meta') / join(configDir, 'contexts', 'tls')

This matches the CLI: https://docs.docker.com/reference/cli/docker/#environment-variables

Notes

Neither path misbehaves when DOCKER_CONFIG is unset, which is presumably why it hasn't come up. Affects main as of a4d3867.

Found while adapting the connection logic in docker-client.ts for another client; I haven't opened a PR. This report was written by Claude (AI-generated) and reviewed by me before filing.

Dominant language
TypeScript
Stars
107
Forks
12
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from docker/node-sdk

All issues in docker/node-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.