Docker Compose file cheatsheet
Docker Compose file: Volumes and networks
5 common Docker Compose file tasks.
Use a named volume
Persist data in a volume managed by Docker.
services:
db:
volumes:
- pgdata:/var/lib/postgresql
volumes:
pgdata:
Mount a host folder
Mount source code into a container for development. :ro makes it read-only.
volumes:
- ./src:/app/src
- ./config.yml:/app/config.yml:ro
Create separate networks
Isolate services: the proxy can reach the app, but not the database.
services:
proxy:
networks: [frontend]
app:
networks: [frontend, backend]
db:
networks: [backend]
networks:
frontend:
backend:
Join an existing network
Attach to a network created outside this file.
networks:
shared:
external: true