DevOps Classroom Series – 28/Jun/2020

Docker Networking

  • References: Networking-1, Swarm, Networking-2

  • Docker containter network architecutre is built on set of interfaces/rules called as Container Networking Model (CNM) Preview

  • CNM Constructs:

    1. Sandbox: this is containers network stack with features such as container network interfaces, routing tables and DNS settings
    2. Endpoint: joins sandbox to network
    3. Network: Network is collection of endpoints with connectivity b/w them.
  • CNM Driver Interfaces Preview

  • CNM provides two pluggable and open interfaces

    • Network Driver
    • IPAM (IP Addresss Managment) Drivers
  • Native Network Drivers: docker has a section for network docker network Preview

  • Docker native network drivers:

    • Host: with host driver , a container uses the networking stack of host.
    • Bridge: This is default driver. Connecting multiple containers on the same bridge network in a single host. The containers created by default are connected to bridge network Preview
    • Overlay: This driver creates an overlay network to support multi-host containers.
    • MACVLAN:
    • None
  • Lets experiment.

    • Create a nginx container and execute docker inspect <container-id> Preview
    • now lets inspect bridge network docker network inspect bridge Preview

Bridge Network

  • In docker by default we will have a default bridge network with name bridge.
  • Lets create a new bridge (user-defined bridge)
docker network create --help
docker network create --driver bridge --subnet mybridge


  • So lets create two container inside mybridge network
docker container run -d --name c1 --network mybridge alpine sleep 1d
docker container run -d --name c2 --network mybridge alpine sleep 1d


  • Lets find the ipaddress of the contianer
docker network inspect mybridge


  • Lets ping between container by name and ipaddress
docker container exec c1 ping -c 4 c2
docker container exec c1 ping -c 4


Docker Swarm

  • Docker swarm is docker native orchestration tool which helps in running containers on multi hosts.

  • In the below image assume we have mulitple hosts running containers on their bridge network. Preview

  • Communications between containers on same host are possible but not on multi-hosts Preview

  • In Docker swarm all the machines are referred as nodes. There are two kinds of nodes

    1. Manager node(s)
    2. worker nodes Preview
  • Lets create docker swarm by following steps mentioned over here in the swarm setup

  • Service, task and container Preview

  • Lets create a service to run 3 replicas of httpd in swarm manager

docker service create --replicas 2 --name httpd httpd 

Preview Preview

  • scale the containers Preview
  • create a docker service with ports exposed docker service create --name httpd --replicas 2 --update-delay 10s --publish published=8081,target=80 httpd Preview

Networking in Windows Server

  • Default driver is NAT (equivalent to bridge)
  • Transperent driver is equivalent to host driver

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin