Table of Contents

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:

Networks:

Volumes:

References

See Also

Last updated: 2026-06-19