Compose Applications
Define a multi-container application with explicit health, network, secret, and storage boundaries.
Compose describes services, networks, volumes, configs, and secrets in one file. Use the current Compose Specification and the docker compose command; a top-level legacy version field is not required.
Define the application
The database has no host port. The application reaches it as db:5432 through Compose service discovery. This example assumes the application reads DATABASE_PASSWORD_FILE; adapt the setting to the application’s documented secret-loading mechanism. The application port is bound to host loopback so a host-managed reverse proxy can reach it without exposing it on every interface.
The secret file must not be committed. Compose mounts it into the container, but local file permissions and access to the Docker host remain part of the security boundary.
Validate before starting
Review an unfamiliar Compose file before running it. Bind mounts, host networking, devices, privileged mode, and the Docker socket can give a container extensive access to the host.
Work with the running project
Use service names, not container IP addresses. A recreated container can receive a different IP while retaining the same DNS name.
Understand volume lifecycle
docker compose down removes project containers and networks but keeps named volumes unless --volumes is provided. Treat down --volumes as destructive when a volume contains data.
Health is not readiness for every dependency
A container health check reports the command result inside that container. It does not prove the complete user path works. Verify the public endpoint, critical dependency access, and a representative application operation after deployment.