- What is
Docker Compose docker-compose.yml- Service
Docker Composenetworking- Volume
- Health checks
- Actions
Docker Compose runs multi-container apps from a docker-compose.yml file.
Example of the file: docker-compose.yml.
See also:
Dockerfor generalDockerconcepts (images, containers, etc.).
A service is a named entry under the services: key in docker-compose.yml. It defines how to build or pull an image and run it as a container.
For example, this project defines four services in docker-compose.yml: app, postgres, pgadmin, and caddy.
Docker Compose creates a network where services can reach each other by their service name.
Docs:
A volume is persistent storage managed by Docker. Data in a volume survives container restarts.
Volumes are defined in docker-compose.yml:
volumes:
postgres_data:A service can mount a volume to store data:
services:
postgres:
volumes:
- postgres_data:/var/lib/postgresql/dataA health check is a command that Docker runs periodically to check if a container is healthy.
Other services can wait for a container to be healthy before starting:
services:
app:
depends_on:
postgres:
condition: service_healthy
postgres:
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5-
To stop all running services and remove containers,
docker compose --env-file .env.docker.secret down
-
To stop all running services, remove containers, and remove volumes,
docker compose --env-file .env.docker.secret down -v
-
To stop all running services, remove containers, remove volumes, and remove images,
docker compose --env-file .env.docker.secret down -v --rmi all