Default Network
Compose creates a default network automatically.
yaml
1services:
2 web:
3 # Can reach 'db' by hostname
4 environment:
5 - DATABASE_HOST=db
6 db:
7 image: postgresCustom Networks
yaml
1services:
2 web:
3 networks:
4 - frontend
5 - backend
6
7 api:
8 networks:
9 - backend
10
11 db:
12 networks:
13 - backend
14
15networks:
16 frontend:
17 backend:External Networks
yaml
1networks:
2 existing-network:
3 external: true
4
5services:
6 web:
7 networks:
8 - existing-networkNetwork Aliases
yaml
1services:
2 db:
3 networks:
4 backend:
5 aliases:
6 - database
7 - postgresNow reachable as db, database, or postgres.
