====== Docker Compose ===== Define and run multi-container applications with a single YAML file. > //Docker Compose simplifies managing multiple containers that work together.// ===== Overview ===== Docker Compose allows you to define and run multi-container applications using a single YAML file. Instead of running each container separately, you define all services in one place and start them all with a single command. ===== Basic Structure ===== ```yaml services: web: image: nginx:latest ports: - "8080:80" networks: - app-network db: image: postgres:16 environment: POSTGRES_PASSWORD: example volumes: - postgres-data:/var/lib/postgresql/data networks: - app-network networks: app-network: volumes: postgres-data: ``` ===== Docker Compose Commands ===== ```bash docker compose up -d # Start services in background docker compose down # Stop and remove containers docker compose logs # View logs docker compose ps # List containers docker compose restart # Restart services docker compose up -d --build # Rebuild and start ``` ===== Service Discovery ===== Containers on the same network can reach each other using service names. In the example above, the web container can reach the database at `db:5432`. ===== Key Concepts ===== **Services:** * Define each container as a service * Specify image, ports, volumes, networks * Service name becomes hostname for other containers **Networks:** * Enable communication between containers * Default network created automatically * Custom networks for isolation **Volumes:** * Persist data across container restarts * Named volumes managed by Docker * Bind mounts link host directories ===== References ===== * [[https://docs.docker.com/get-started/workshop/08_using_compose/|Use Docker Compose]] * [[https://docs.docker.com/get-started/docker-concepts/the-basics/what-is-docker-compose/|What is Docker Compose?]] * [[https://linuxize.com/post/docker-compose/|Docker Compose: Define and Run Multi-Container Apps]] * [[https://docs.docker.com/reference/compose-file/services/|Define services in Docker Compose]] ===== See Also ===== * [[hosting:docker:start|Docker Overview]] * [[hosting:docker:concepts|Basic Docker Concepts]] Last updated: 2026-06-19 * [[hosting:start|Return to hosting]]