Skip to main content

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

  1. Use .env files for sensitive information.
  2. Use named volumes for persistent data.
  3. Define networks to isolate services.
  4. Set restart: always when high availability matters.
  5. Use depends_on to declare dependencies.
  6. Add health checks.
  7. Use deploy.resources to limit resources when appropriate.

References

Last modified on April 17, 2026