Skip to content

fix(docker): pin the compose project name - #9

Merged
tmlksu merged 1 commit into
mainfrom
fix/compose-project-name
Aug 31, 2026
Merged

tmlksu merged 1 commit into
mainfrom
fix/compose-project-name

Conversation

@tmlksu

@tmlksu tmlksu commented Aug 31, 2026

Copy link
Copy Markdown
Owner

何が起きるか

compose のプロジェクト名は、既定では compose ファイルのあるディレクトリ名 から決まる。ここでは docker になる。docker/ の下に compose を置くリポジトリはいくらでもあるので、そういうものが 1 台のマシンに 2 つあると同じプロジェクトと見なされる。片方で up -d を叩くと、同一サービス名のもう片方のコンテナが recreate される。down なら消える。

仮の話ではない。 このマシン上で、別リポジトリが動かしていた本番の WebDAV ゲートウェイをこれで破壊した。しかも up -d の出力に出る Container <相手の名前> Recreated は、これから起動する自分のコンテナのログに紛れて読み飛ばしやすい。

直したあとの挙動

プロジェクト名を固定すると、衝突はポートの bind 失敗として出る:

Error response from daemon: ... Bind for 127.0.0.1:8080 failed: port is already allocated

うるさいが、相手には触らない。これが正しい失敗の仕方。

確認

本番コンテナを動かしたまま、こちらで up -d を叩いて検証した:

本番 (前): 6b9729dc0d5f... 2026-08-31T03:18:22Z
→ up -d は port is already allocated で失敗
本番 (後): 6b9729dc0d5f... 2026-08-31T03:18:22Z   ← ID・起動時刻とも同一
PROPFIND -> 207

並走させたい場合のポート変更も実際に確かめた (DAV_BIND_PORT=8090 で live.mjs 66/66 通過、その間 8080 の本番は 207 のまま)。手順は docker/README.md に書いた。

compat 側にも入れた

docker/compat/compose.yml は down --remove-orphans を掛けるので、プロジェクトを取り違えたときの破壊力はこちらのほうが大きい。

🤖 Generated with Claude Code

Compose derives the project name from the directory holding the file, which
here is `docker` — a name any number of repositories will produce. Two of them
on one machine share a project, and `up -d` in either one recreates the other's
containers under the same service name; `down` removes them.

This is not hypothetical. It destroyed a running WebDAV gateway belonging to a
different repository on this machine, and the recreate scrolled past looking
like normal startup output for the container that was being started.

With the name pinned the collision surfaces as a port bind failure instead —
loud, and harmless to whatever is already there. docker/README.md explains the
trade and points at DAV_BIND_PORT for running alongside another server.

The compat stack gets a name too. It runs `down --remove-orphans`, so
misidentifying its project is the more destructive of the two.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tmlksu
tmlksu merged commit 16e5213 into main Aug 31, 2026
3 checks passed
@tmlksu
tmlksu deleted the fix/compose-project-name branch August 31, 2026 03:21
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.

1 participant