Swarm local-node versus swarm overlay networks (DOCKER CE 17.06)

#creating docker-in-docker nodes

docker network create my-swarm-net-1
docker run -dit — privileged — network my-swarm-net-1 — name manager1 -d docker:17.06.0-ce-rc5-dind
docker run -dit — privileged — network my-swarm-net-1 — name worker1 -d docker:17.06.0-ce-rc5-dind
docker run -dit — privileged — network my-swarm-net-1 — name worker2 -d docker:17.06.0-ce-rc5-dind

#creating a docker-in-docker swarm cluster

$ docker exec -it manager1 sh 
/ # docker swarm init
Swarm initialized: current node (ycm44rxgd9pmmtdy2sdfvjcoa) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join — token SWMTKN-1–4uxf3fed8bxbkuv1z1qms0lg23n0tgpibf14ubgbgsxsjrilcn-3bi6eekip5yjtlvisdac06u4o 172.18.0.2:2377

To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.

/ #

$ docker exec -it worker1 sh
/ # docker swarm join — token SWMTKN-1–4uxf3fed8bxbkuv1z1qms0lg23n0tgpibf14ubgbgsxsjrilcn-3bi6eekip5yjtlvisdac06u4o 172.18.0.2:2377
This node joined a swarm as a worker.
/ #

$ docker exec -it worker2 sh
/ # docker swarm join — token SWMTKN-1–4uxf3fed8bxbkuv1z1qms0lg23n0tgpibf14ubgbgsxsjrilcn-3bi6eekip5yjtlvisdac06u4o 172.18.0.2:2377
This node joined a swarm as a worker.
/ #

#creating swarm local network config

$ docker exec -it worker1 sh
/ # docker network create — config-only=true — subnet=”10.1.0.0/16" local-config

$ docker exec -it worker2 sh
/ # docker network create — config-only=true — subnet=”10.2.0.0/16" local-config

$ docker exec -it manager1 sh 
/ # docker network create — scope=swarm — config-from=local-config — driver bridge mynet
/ # docker service create — network mynet — name www nginx 
/ # docker service scale www=4

On worker1
/ # docker inspect — format ‘{{ .NetworkSettings.Networks.mynet.IPAddress }}’ $(docker ps -q)
10.1.0.3
10.1.0.2
/ #

On worker2
/ # docker inspect — format ‘{{ .NetworkSettings.Networks.mynet.IPAddress }}’ $(docker ps -q)
10.2.0.3
10.2.0.2
/ #

Please note that all container in service www are in a seperate per host ip subnet

# In contrast with a swarm overlay (one stretched vlan including manager node)

$ docker exec -it manager1 sh 
/ # docker network create — scope=swarm — driver overlay mynet6
/ # docker service create — network mynet6 — name www nginx 
/ # docker service scale www6=4

On worker1
/ # ddocker inspect — format ‘{{ .NetworkSettings.Networks.mynet6.IPAddress }}’ $(docker ps -q)
10.0.0.5
/ #

On worker2
/ # docker inspect — format ‘{{ .NetworkSettings.Networks.mynet6.IPAddress }}’ $(docker ps -q)
10.0.0.6
/ #

On manager1
/ # docker inspect — format ‘{{ .NetworkSettings.Networks.mynet6.IPAddress }}’ $(docker ps -q)
10.0.0.4
10.0.0.3
/ #

Please note that all container in service www6 are in the 10.0.0.0/16 network

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.