Overlay Multi-Host Networking
- Just choose
--driver overlay
when creating network
- For container-to-container traffic inside a single Swarm
- Optional IPSec (AES) encryption on network creation
- Each service can be connected to multiple networks
- (e.g. front-end, back-end)
Example usage
- Create a new overlay network
[node1] ~> docker network create --driver overlay
ffbzfzxwfxwh1jex2ovky2wil
[node1] ~> docker network ls
NETWORK ID NAME DRIVER SCOPE
64f4be5e2bbc bridge bridge local
9b9ee0e5dd9c docker_gwbridge bridge local
eafbd0580460 host host local
pti3tm6t2sr7 ingress overlay swarm
ffbzfzxwfxwh mydrupal overlay swarm
a6ee62ad8781 none null local
[node1] ~> docker service create --name psql --network mydrupal -e POSTGRES_PASSWORD=mypass postgres
y5v2pro56rtl0xagakxnz4vt3
[node1] ~> docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
y5v2pro56rtl psql replicated 1/1 postgres:latest
[node1] ~> docker service ps y5v2pro56rtl
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
tswse0npw0i7 psql.1 postgres:latest node1 Running Running 2 minutes ago
[node1] ~> docker service create --name drupal --network mydrupal -p 80:80 drupal
854hpf1t4w9urlvb7uvdww0cd
[node1] ~> docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
854hpf1t4w9u drupal replicated 1/1 drupal:latest *:80->80/tcp
y5v2pro56rtl psql replicated 1/1 postgres:latest
[node1] ~> docker service ps drupal
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
hqbo9ejku1yo drupal.1 drupal:latest node2 Running Running 47 seconds ago
- You can connect to drupal on any of the nodes IPs which is kinda cool