ip能通 name通不了
来源:4-5 容器之间的link
hechong
2020-04-15
docker run -d --name test1 busybox /bin/sh -c "while true; do sleep 3600; done"
docker run -d --name test2 busybox /bin/sh -c "while true; do sleep 3600; done"
sudo docker network create -d bridge my-bridge
docker run -d --name test3 --network my-bridge busybox /bin/sh -c "while true; do sleep 3600; done"
sudo docker network connect my-bridge test2
docker exec -it test3 /bin/sh
ping test2
3回答
-
麦兜搞IT
2020-04-18
您好,您可以看一下我的执行记录,我刚完全按照您的步骤试了一遍,没有问题
00 -
麦兜搞IT
2020-04-18
$ docker run -d --name test1 busybox /bin/sh -c "while true; do sleep 3600; done" fbac51e214709f7f737e8686cece8e05ae7d1b079b8f5ba385ee2425bcb6db92 $ $ $ docker run -d --name test2 busybox /bin/sh -c "while true; do sleep 3600; done" 5fcd1e39f339b71cade5df24696e60d419698f6e614169f48e0203e5d1756e57 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5fcd1e39f339 busybox "/bin/sh -c 'while t…" 2 seconds ago Up 1 second test2 fbac51e21470 busybox "/bin/sh -c 'while t…" 17 seconds ago Up 17 seconds test1 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5fcd1e39f339 busybox "/bin/sh -c 'while t…" 14 seconds ago Up 13 seconds test2 fbac51e21470 busybox "/bin/sh -c 'while t…" 29 seconds ago Up 28 seconds test1 $ docker network ls NETWORK ID NAME DRIVER SCOPE d27ac14ccc04 bridge bridge local 150841b609a5 host host local 14bf23e2f5c4 my-bridge bridge local f4eaa1069314 none null local $ docker run -d --name test3 --network my-bridge busybox /bin/sh -c "while true; do sleep 3600; done" 91ecbbfd9290b4c4007dd24c632a62403ee1c73b0c32b593c787552fd84ac500 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 91ecbbfd9290 busybox "/bin/sh -c 'while t…" 2 seconds ago Up 2 seconds test3 5fcd1e39f339 busybox "/bin/sh -c 'while t…" 31 seconds ago Up 30 seconds test2 fbac51e21470 busybox "/bin/sh -c 'while t…" 46 seconds ago Up 46 seconds test1 $ docker network connect my-bridge test2 $ docker exec -it test3 sh / # ping test2 PING test2 (172.22.0.3): 56 data bytes 64 bytes from 172.22.0.3: seq=0 ttl=64 time=0.178 ms 64 bytes from 172.22.0.3: seq=1 ttl=64 time=0.170 ms ^C --- test2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.170/0.174/0.178 ms / #
012021-05-08 -
再也不上QQ鸟
2020-04-18
测试了一下你的代码,是可以拼通的。你最好把test1,test2,test3都删掉,再试一下
[vagrant@docker-node1 etcd-v3.0.12-linux-amd64]$ docker run -d --name test1 busybox /bin/sh -c "while true; do sleep 3600; done"
8303402334ceb6d335502fe7733c7f434085054525c1dc91a9838baae990134c
[vagrant@docker-node1 etcd-v3.0.12-linux-amd64]$ docker run -d --name test2 busybox /bin/sh -c "while true; do sleep 3600; done"
875895a272e9ae1230fe5a0b126794d7062d8ff824b5647a4b3ca16e78cff146
[vagrant@docker-node1 etcd-v3.0.12-linux-amd64]$ sudo docker network create -d bridge my-bridge
5efe3507ee495b96160c8b7434fd685f6ce1c7343e1546ca460cbef75c019a6a
[vagrant@docker-node1 etcd-v3.0.12-linux-amd64]$ docker run -d --name test3 --network my-bridge busybox /bin/sh -c "while true; do sleep 3600; done"
3bb6beb90d9be612c476635dba826e5307f8ac63adc22385483d5028e151d93a
[vagrant@docker-node1 etcd-v3.0.12-linux-amd64]$ sudo docker network connect my-bridge test2
[vagrant@docker-node1 etcd-v3.0.12-linux-amd64]$ docker exec -it test3 /bin/sh
/ # ping test2
PING test2 (172.20.0.3): 56 data bytes
64 bytes from 172.20.0.3: seq=0 ttl=64 time=0.162 ms
64 bytes from 172.20.0.3: seq=1 ttl=64 time=0.121 ms
64 bytes from 172.20.0.3: seq=2 ttl=64 time=0.071 ms
64 bytes from 172.20.0.3: seq=3 ttl=64 time=0.200 ms
^C
--- test2 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.071/0.138/0.200 ms
/ #
012020-04-18
相似问题