docker networking example

1. List the docker network.

# docker network ls


82f0e82e8a52 bridge bridge local

2f29f6c3dc07 host host local

0ee77fd0eaf6 none null local

2. List the bridge's address.

# ifconfig docker0 | grep "inet "

inet netmask broadcast

3. Create two containers.

# docker run -d -it --name=container1 net/centos

# docker run -d -it --name=container2 net/centos

4. List the address of container1.

# docker exec container1 ifconfig eth0 | grep "inet "

inet netmask broadcast

5. Create a new network.

# docker network create -d bridge --subnet \ isolated_nw

6. Connect container2 to the new network.

# docker network connect isolated_nw container2

7. List the addresses of container2.

# docker exec container2 ifconfig | grep "inet "

inet netmask broadcast

inet netmask broadcast

inet netmask

8. Create a third container and connect it to the new network.

# docker run --network=isolated_nw --ip= -itd \ --name=container3 net/centos

9. Check connectivity from container2 to container3.


# docker exec container2 ping -w 1

PING ( 56(84) bytes of data.

64 bytes from icmp_seq=1 ttl=64 time=0.088 ms

64 bytes from icmp_seq=2 ttl=64 time=0.072 ms

10 Check connectivity from container3 to container1.

# docker exec container3 ping -w 1

PING ( 56(84) bytes of data.

--- ping statistics ---

2 packets transmitted, 0 received, 100% packet loss, time 999ms

11. Clean up.

# docker rm -f container1 container2 container3




# docker network rm isolated_nw



This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.