测试了一下你的代码,是可以拼通的。你最好把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
/ #