Docker Bridge and Overlay Network with Compose Variable Substitution

Docker Multi-Host networking allows you to create virtual networks and attach containers to them so you can create the network topology that is right for your application. Bridge networks can be created for single host and overlay networks can be created for multiple hosts. Creating application-specific networks provides complete isolation for containers.

Docker Compose file can be targeted at a single host, and --x-networking will create a bridge network exclusive for the application. If the sample application is targeted at multiple hosts, say using Docker Swarm cluster, then an overlay network is created. Single host networking and multi host networking provide more details on how to set this up.

What if a bridge or an overlay network already exists and you’d like to assign this to your application started using Docker Compose?

Docker 1.9 introduced variable substitution, and we can use that feature to target an application to a pre-created network.

Create New Docker Bridge Network

Create a new network:

1

2

3

4

docker network create-dbridge mynet

47d6225ffe56ddd1a8bc0d6abb0ffd8f8ac3eec2090ff243f8cd6f77c170751b=

List the networks:

1

2

3

4

5

6

7

8

docker network ls

NETWORK ID NAME DRIVER

feb6e9567439 bridge bridge

29563a59abe8none null

25ab737cd665host host

47d6225ffe56mynet bridge

Docker create three networks for each host automatically:

NETWORK NAME

PURPOSE

bridge

Default network that containers connect to. This is docker0 network in all Docker installations.

none

Container-specific networking stack

host

Adds a container on hosts networking stack. Network configuration is identical to the host.