bridge
デフォルトと比較して、カスタムネットワークbridge
はコンテナ名を使用できますping
カスタムbridge
ネットワークを作成する
[root@localhost claroja]# docker network create --driver bridge my_bridge
90aae60129bbf437e5b5747485aacd15b4a18c3b170819460f687ebf7a2acef1
[root@localhost claroja]# docker network ls
NETWORK ID NAME DRIVER SCOPE
3c145f070fd7 bridge bridge local
f0428b4ac8ec host host local
90aae60129bb my_bridge bridge local
42c2aaaeac08 none null local
カスタムネットワークをbridge
使用してコンテナを作成し、--ip
パラメータを使用して固定IPを指定できます
[root@localhost claroja]# docker container run --name test1 --net=my_bridge -dit centos /bin/bash
29dca61dfb1b17cb7820829484a49d4c551329fe2e3570a1fa15b7f59a9d5a8a
[root@localhost claroja]# docker container run --name test2 --net=my_bridge -dit centos /bin/bash
365f70df607e754c2442d97bf636de9181a5bb47e8217994e5179c728e7a3322
コンテナを入力してください。test1
コンテナ名を直接使用して、ping
[root@localhost claroja]# docker attach test1
[root@29dca61dfb1b /]# ping test2
PING test2 (172.18.0.3) 56(84) bytes of data.
64 bytes from test2.my_bridge (172.18.0.3): icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from test2.my_bridge (172.18.0.3): icmp_seq=2 ttl=64 time=0.051 ms
参照:
https ://www.cnblogs.com/zuxing/articles/8780661.html
https://blog.51cto.com/shyln/2133385