Docker Compose
Define and run multi-container applications using a declarative YAML configuration file.
Description
Docker Compose is a tool for defining and running multi-container Docker applications using a declarative YAML file (compose.yaml or docker-compose.yml). It allows developers to specify services, networks, volumes, environment variables, and dependencies in a single file, then bring the entire application stack up or down with a single command. This is particularly valuable for local development environments that mirror production architectures.
Compose supports service dependencies with depends_on and health check-based startup ordering, ensuring databases and message brokers are ready before application services start. It manages named volumes for persistent data, custom bridge networks for service isolation, and bind mounts for development hot-reloading. Environment variables can be injected from .env files, shell environment, or inline definitions with variable substitution.
Modern Docker Compose v2 (integrated as a Docker CLI plugin) supports profiles for selectively enabling services, extends for sharing common configuration, and watch mode for automatic rebuilds during development. It also supports deploy configuration for resource constraints, replicas, and restart policies, making it useful for single-node production deployments and as a stepping stone toward orchestration platforms.
Prompt Snippet
Define a compose.yaml with services for the application (build from local Dockerfile), PostgreSQL 16 with a named volume for data persistence, and Redis 7 for caching. Use healthcheck-based depends_on conditions (service_healthy) to enforce startup ordering. Configure a custom bridge network, load environment variables from a .env file with variable interpolation, set memory limits via deploy.resources.limits, and use profiles to optionally include monitoring services (Grafana, Prometheus) only in development.
Tags
Related Terms
Docker Containerization
Package applications and their dependencies into isolated, portable containers using Docker.
Dockerfile Best Practices
Write efficient, secure, and maintainable Dockerfiles that produce minimal, production-ready images.
Environment Variable Management
Externalize application configuration into environment variables to separate config from code across environments.
Container Orchestration (Kubernetes basics)
Automate deployment, scaling, and management of containerized applications using Kubernetes.