15
14

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 5 years have passed since last update.

DockerコンテナのIPを取得する方法(docker inspectコマンド編)

Posted at

昔のバージョンはこういう方法が流行っていましたが、

docker inspect 49ddbb6b8e91 | grep IPAddress | cut -d '"' -f 4

最新のDockerではinspectコマンドに'-f'というオプションが追加したらしい。下記はマニュアルからの抜粋。

Usage: docker inspect CONTAINER|IMAGE [CONTAINER|IMAGE...]

Return low-level information on a container/image

  -f, --format=""    Format the output using the given go template.

すなわち、IPアドレスはこうのように取得出来ます。

docker inspect -f "{{ .NetworkSettings.IPAddress }}" $ID

-fオプションは自由度の高いtext/templateとなっているため、思う通りなんでもカスタマイズできると思います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?