Skip to content

fix: 別の worktree の開発コンテナと同時に起動できるようにする - #44

Merged
shin4488 merged 1 commit into
mainfrom
fix/compose-parallel-worktrees
Oct 4, 2026
Merged

shin4488 merged 1 commit into
mainfrom
fix/compose-parallel-worktrees

Conversation

@shin4488

@shin4488 shin4488 commented Oct 4, 2026

Copy link
Copy Markdown
Owner

docker-compose.yml はコンテナ名を container_name: algorithm-visualizer-dev に固定していました。Compose はディレクトリ名からプロジェクト名を決めるので、git worktree はそれぞれ別のプロジェクトになります。それなのに、どのプロジェクトも同じ名前のコンテナを作ろうとするため、別の worktree に停止中のコンテナが残っているだけで docker compose up -d --build が失敗していました。

変更

  • container_name を削除しました。コンテナ名は <プロジェクト名>-app-1(例:compassionate-pike-ddb08f-app-1)になります。固定名を参照している箇所はありません。ドキュメント・.husky/pre-commit・devcontainer.json はいずれもサービス名 app を使っており、docker compose exec app などはそのまま動きます。
  • 名前が衝突しなくなっても、ホスト側のポート 1234 が固定のままだと、2 つの worktree を同時に起動できません(Bind for 0.0.0.0:1234 failed: port is already allocated)。そこで、DEV_PORT でホスト側のポートだけを変えられるようにしました。既定値は 1234 のままです。コンテナ内の Parcel は 1234 で待ち受けたままです。
  • README の「Using Docker Compose」に DEV_PORT の使い方を追記し、AGENTS.md からその節を参照するようにしました。
  • compose ファイル 1 行目の typo(ifrst → first)を直しました。

HMR は、Parcel のクライアントが「HMR ポート=配信ポート」のときにページ自身のポート(location.port)へ接続する実装(@parcel/runtime-browser-hmr)なので、ホスト側のポートを付け替えても動きます。

既存の algorithm-visualizer-dev コンテナは、同じプロジェクトで次に docker compose up したとき新しい名前で作り直される想定です(未確認)。

検証

Docker Compose v2.6.1(Docker Desktop for Mac)で確認しました。

  • docker compose config:既定では published: "1234"、DEV_PORT=1235 では "1235" になることを確認しました。
  • 必須チェック:docker compose up -d --build で作ったコンテナで、yarn typecheck・yarn lint・yarn format・yarn test(26 件)がすべて成功しました。
  • 同時起動:この worktree(1234)と、別ディレクトリにコピーした checkout(DEV_PORT=1235)を同時に起動し、どちらも /ja/・/en/ が 200 を返しました。DEV_PORT なしで 2 つ目を起動すると、上記のポート衝突エラーで止まることも確認しています。
  • HMR:1234 と 1235 のそれぞれで、ブラウザを開いたまま src/styles.css を一時的に変更し、元に戻しました。どちらも、ページを再読み込みせずに反映されました(window に置いた目印の値が残ったままでした)。fix: 開発コンテナの yarn build が開発版の React を同梱しないようにする #43 を取り込んだ後の構成でも、1235 で同じ結果になりました。
  • 機密情報:コミットを gitleaks で確認し、検出はありませんでした。

🤖 Generated with Claude Code

docker-compose.yml pinned container_name to algorithm-visualizer-dev.
Compose names each project after its directory, so every git worktree
is a separate project, yet all of them tried to create a container
with that one name. A stopped container left by another worktree was
enough to make `docker compose up -d --build` fail. Nothing refers to
the fixed name: the docs, the pre-commit hook and the devcontainer all
address the `app` service. Drop it so Compose names the container
`<project>-app-1`.

With the names no longer clashing, the fixed host port is what still
stops two worktrees from running at once. Let DEV_PORT change the
published host port while Parcel keeps listening on 1234 inside the
container. Parcel's HMR client connects to the page's own port when the
HMR port matches the serve port, so HMR keeps working on a remapped
port. Document DEV_PORT in the README and point to it from AGENTS.md.

Also fix the "ifrst" typo in the compose header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shin4488
shin4488 merged commit 17f50d2 into main Oct 4, 2026
5 checks passed
@shin4488
shin4488 deleted the fix/compose-parallel-worktrees branch October 4, 2026 07:31
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