Set default network name for compose
With the latest release of Docker-Compose (1.18) they added the possibility to achieve exactly this – i.e. setting a global unique name for networks from a docker-compose.yml. Although it is not terribly well documented, you can read the docs for this change -> https://docs.docker.com/compose/compose-file/#name-1
You need at least Docker Engine 17.06.0 for this to work. If you have both – recent Docker Engine and a still hot docker-compose 1.18 you can achieve it with:
# you need to use the latest version of docker-compose yml
version: '3.5'
services:
app:
image: nginx
networks:
- my-network-name
networks:
my-network-name:
name: my-global-net
This will create the global net my-network-name
. Seems like setting the same global network from different docker-compose.yml does not have any effects (nor an error is displayed); although I presume that then all services will obviously in the same overlay network.
N.B. docker-compose down
will try to remove the global network.