2
1

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で立ち上げたコンテナに外から通信する

Last updated at Posted at 2021-01-13

背景

docker-composeで立ち上げたDBコンテナに他のコンテナからconnectionを貼りたかった
その手順の備忘録

手順

以下のコマンドでdocker-composeで立ち上げたnetworkIDとNameを調べる

$ docker network ls

docker runコマンドで先程取得したID or Nameを--netで指定して実行

$ docker run -it -v "$PWD":/path/to/dir --net <network ID or Name> <image名> <command>

これで指定したネットワーク先のホストやエイリアスで接続できる

ホスト名がない場合は--linkでエイリアスを作成する

$ docker run -it -v "$PWD":/path/to/dir --net <network ID or Name> --link <container Name>:<host Name> <image名> <command>
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?