Do not conflate external: true
with internal: false
. To allow separate compose projects to share a network connection AND have that network be automatically created, simply specify a matching network name
in each compose file.
when set to true allow to create an externally isolated network
By default, networks are NOT internal and thus already provide external connectivity.
If set to true, external specifies that this network’s lifecycle is maintained outside of that of the application.
The external
property refers to how the network is managed and does NOT describe its connectivity or lack thereof.
external: false
:
- is the default and can be omitted
- allows a network to be auto-created as needed
- will not throw an error if the network was previously auto-created by another running stack
Absent a specified name
attribute, auto-created networks use the key prefixed with the project name. Explicitly setting the name prevents project scoping and allows for shared use.
Example
project1
services:
db:
networks:
service_tier:
aliases:
- remotedb
networks:
service_tier:
name: service_tier
project2
services:
web:
networks:
service_tier:
networks:
service_tier:
name: service_tier
Result
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
ca564d4e76e6 bridge bridge local
6b4d2866afa8 host host local
15fa57f54e0b project1_default bridge local
a5eb24fc02b0 project2_default bridge local
d4b0a10c1385 service_tier bridge local
614c5864df80 none null local
In this configuration the web
service in project2
can reach the db
service in project1
by using the host alias remotedb
on the shared service_tier
network.
Without name
in the networks
sections you would see separate project1_service_tier
and project2_service_tier
instead and communication would not be possible.