Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications through YAML service definitions.
Installation
Docker Desktop already includes Docker Compose.
Standalone Linux installation
Basic commands
docker-compose.yml syntax
Basic Structure
Common configuration fields
image: image to use
build: builtConfiguration
ports: Port Mapping
volumes: volume mounts
environment: Environment Variables
depends_on: Dependencies
networks: network configuration
restart: restart policy
command: override the default command
Common service configurations
MySQL
Redis
PostgreSQL
MongoDB
Nginx
Open WebUI
Full web application stack
Environment Variablesfile
Create a .env file:
Use it in docker-compose.yml like this:
Practical Tips
View service logs
Scale services
Rebuild only a specific service
Clean up resources
Best Practices
- Use
.env files for sensitive information.
- Use named volumes for persistent data.
- Define networks to isolate services.
- Set
restart: always when high availability matters.
- Use
depends_on to declare dependencies.
- Add health checks.
- Use
deploy.resources to limit resources when appropriate.
References
Last modified on April 17, 2026