コンテナの内部IPアドレスを確認する方法
コンテナの内部IPアドレスを確認するにはdocker container inspectコマンド実行します。
コマンドの説明
$ docker container inspect --help Usage: docker container inspect [OPTIONS] CONTAINER [CONTAINER...] Display detailed information on one or more containers Options: -f, --format string Format the output using the given Go template -s, --size Display total file sizes
実行例
$ docker container run -itd --name test01 centos:7.7.1908 /bin/bash 301dc60e4b91daf186651c215780a948d970de90df0fedea908fbbb8de80e167 $ docker container inspect -f "{{.NetworkSettings.IPAddress}}" test01 # -fでIPアドレス部分のみを取得 172.17.0.3 $ docker container exec -it test01 hostname -i # またはhostname -iを実行 172.17.0.3 $ ping -c 3 172.17.0.3 PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data. 64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.078 ms 64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.052 ms 64 bytes from 172.17.0.3: icmp_seq=3 ttl=64 time=0.056 ms --- 172.17.0.3 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2008ms rtt min/avg/max/mdev = 0.052/0.062/0.078/0.011 ms