Services

Define services using Docker Compose syntax. Databases, caches, APIs—anything that runs in a container can be deployed to your environment.

Composition

docker-compose.yml
services:
  postgres:
    image: postgres:16
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

volumes:
  postgres_data:

Images & Ports

Images

image: postgres:16
image: ghcr.io/org/api:latest

Ports

- "5432:5432" # host:container
- "3000:8080" # map 8080 to 3000

Volumes

Named Volumes

- postgres_data:/var/lib/postgresql/data

Persist data across restarts

Config Files

- /files/nginx.conf:/etc/nginx/nginx.conf

Mount files using /files/ prefix

Networking

Services communicate using service names as hostnames. DNS resolution is automatic.

postgres://user:pass@postgres:5432/db
redis://redis:6379
http://api:8080/health