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

オープン 初心者向け
#76 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, typescript
領域
devops

調査の方向性

lib/docker-client.ts の fromDockerConfig と fromDockerContext から始め、各エントリポイントが DOCKER_CONFIG とデフォルトのホームディレクトリパスをどのように解決しているかを追ってください。完了条件は、DOCKER_CONFIG が設定されていない場合の動作を維持しつつ、両方のエントリポイントが config.json と contexts のパスを含め、Docker の設定ディレクトリを一貫して使用することです。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
107
フォーク
12
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker/node-sdk のほかの issue

docker/node-sdk の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。