1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Docker composeのコンテナ間通信でハマったとこ

Posted at

MacでコンテナごとにIPを割り当てられない

docker (Linux) ブリッジ・ネットワークは macOS ホストから到達できません。
https://docs.docker.jp/docker-for-mac/networking.html#ip

host.docker.internalをホスト名に指定するといい

version: "3"
services:
  api:
    build: .
    ports:
      - 8080:8080
  web:
    build: .
    environment:
      - API_HOST_NAME=host.docker.internal:8080

順番通りに起動してくれない

このようにdepends_onで起動順は制御できますが接続可能になるまでは待ってくれません

version: "3"
services:
  api:
    build: .
  web:
    build: .
    depends_on:
      - api

wait-for-itなどを使って、以下のようにコマンドを指定するといいです

version: "3"
services:
  api:
    build: .
  web:
    build: .
    depends_on:
      - api
    command: ["./wait-for-it.sh", "<コンテナ名>:<ポート番号>", "--", "<接続時に実行するコマンド>"]

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?