How do i group containers onto a user defined network bridge?
-
Man page on docker network create: http://bit.ly/2hNAs90
Man page on docker run: http://bit.ly/2h77MqOFirst start by creating a new network.
$ docker network create frontend
Run a container to connect to the network you just created and sleep for 120 seconds.
$ docker run -d --network frontend --network-alias fe --name webserver1 alpine sleep 120
Run another container to ping the webserver1 container above.
$ docker run --network frontend alpine ping -c 1 webserver1 PING webserver1 (172.18.0.2): 56 data bytes 64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.073 ms --- webserver1 ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0.073/0.073/0.073 ms
Do the same but use the network alias to ping.
$ docker run --network frontend alpine ping -c 1 fe PING fe (172.18.0.2): 56 data bytes 64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.070 ms --- fe ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0.070/0.070/0.070 ms
All containers communicate on the same network called frontend.
© Lightnetics 2024