# Docker Compose — Define and Run Multi-Container Applications > Docker Compose lets you define multi-container application stacks in a single YAML file and manage their full lifecycle with simple CLI commands. ## Install Save as a script file and run: # Docker Compose — Define and Run Multi-Container Applications ## Quick Use ```bash # Install (included with Docker Desktop, or standalone) sudo apt-get install docker-compose-plugin # Start services defined in docker-compose.yml docker compose up -d # Stop and remove containers docker compose down ``` ## Introduction Docker Compose simplifies multi-container application development by letting you define services, networks, and volumes in a single `docker-compose.yml` file. It bridges the gap between writing Dockerfiles for individual containers and orchestrating them as a cohesive application stack. ## What Docker Compose Does - Defines multi-container applications in a declarative YAML format - Manages container lifecycle (build, start, stop, restart, destroy) with single commands - Creates isolated networking between services automatically - Supports volume management for persistent data across restarts - Enables environment-specific overrides via multiple Compose files ## Architecture Overview Docker Compose V2 is a Go-based CLI plugin for the Docker CLI, replacing the original Python implementation. It reads `docker-compose.yml` files, translates service definitions into Docker API calls, and coordinates container creation with proper dependency ordering. Compose communicates directly with the Docker Engine API and manages a project namespace that groups related resources. ## Self-Hosting & Configuration - Included in Docker Desktop for macOS and Windows; install the `docker-compose-plugin` package on Linux - Configuration lives in `docker-compose.yml` (and optional override files like `docker-compose.override.yml`) - Use `.env` files for variable substitution in Compose files - Supports build-time arguments, health checks, resource limits, and restart policies - Profiles allow selective service activation for different workflows (e.g., debug, test) ## Key Features - Watch mode (`docker compose watch`) for automatic rebuilds during development - Built-in support for GPU resources and platform-specific images - Compose Build integrates with BuildKit for efficient multi-stage and cached builds - Service dependency management with `depends_on` and health check conditions - Native integration with Docker Swarm for single-node production deployments ## Comparison with Similar Tools - **Kubernetes** — full orchestration for distributed clusters; Compose targets single-host or development use - **Podman Compose** — drop-in alternative using Podman instead of Docker Engine - **Docker Swarm** — built-in Docker clustering; Compose files can deploy to Swarm with `docker stack deploy` - **Dockge** — web UI wrapper around Compose for visual management - **Kompose** — converts Compose files to Kubernetes manifests for migration ## FAQ **Q: Is Docker Compose V2 backward-compatible with V1?** A: Mostly yes. V2 supports the same file format but uses `docker compose` (space) instead of `docker-compose` (hyphen). A few edge-case behaviors differ. **Q: Can I use Compose in production?** A: Compose works well for single-server deployments. For multi-node production, consider Kubernetes or Docker Swarm. **Q: How do I manage secrets in Compose?** A: Use the `secrets` top-level element to reference files or environment variables, avoiding hardcoded values in the YAML. **Q: Does Compose support GPU passthrough?** A: Yes. Use the `deploy.resources.reservations.devices` section to specify GPU access per service. ## Sources - https://github.com/docker/compose - https://docs.docker.com/compose/ --- Source: https://tokrepo.com/en/workflows/asset-07825c60 Author: Script Depot