15
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dockerでコンテナがどのネットワークに属しているのかを調べたい

Last updated at Posted at 2025-03-22

はじめに

この記事は、ほぼ自分のメモのための記事です。
ですが、自分と同じような悩みをお持ちの方はご参考にどうぞ。

本題

最近、システムで利用しているデータベースについて、

SchemaSpy

を利用してDDLを作成しようと思ったのですが、「対象のコンテナがどのネットワークに属しているのかわからん。」

という事態になったので、調査のために以下のコマンドを作成しました。

docker network ls --format '{{.Name}}' | while read network; do
  echo "Network: $network"
  docker network inspect "$network" --format '{{range .Containers}}{{.Name}}{{"\n"}}{{end}}' | sed '/^$/d'
done

出力結果

Network: host
Network: hogehoge_default
Network: hogefuga_default
Network: fugafuga_default
fugafuga-web
fugafuga-redis
fugafuga-app
fugafuga-db
fugafuga-storage

これで、DDLを作成しようとしているDBコンテナが、「fugafuga_default」というネットワークに属していることがわかりました。

ネットワークに属しているコンテナが存在しないときは、何も表示されません。
例「hogehoge_default」

みなさんも、自分のDockerコンテナがどのネットワークに属しているのか知りたくなったときは利用してみてはいかがでしょうか。

以上です。

15
5
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
15
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?