---
title: "Docker Compose"
description: "Docker Compose configuration for TraceRTM development"
keywords: [docker, docker-compose, containers, development]
---

# Docker Compose

Docker Compose configuration for running TraceRTM with all dependencies.

## docker-compose.yml

### Basic Configuration

```yaml
version: '3.8'

services:
  api:
    build: .
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=postgresql://postgres:password@db:5432/tracertm
      - REDIS_URL=redis://redis:6379/0
    depends_on:
      - db
      - redis
    volumes:
      - ./src:/app/src

  db:
    image: postgres:14
    environment:
      - POSTGRES_DB=tracertm
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data

volumes:
  postgres_data:
  redis_data:
```

## Usage

### Start Services

```bash
# Start all services
docker-compose up -d

# Start with logs
docker-compose up

# Start specific service
docker-compose up db
```

### Stop Services

```bash
# Stop services
docker-compose stop

# Stop and remove
docker-compose down

# Remove volumes
docker-compose down -v
```

### View Logs

```bash
# All services
docker-compose logs -f

# Specific service
docker-compose logs -f api

# Last 100 lines
docker-compose logs --tail=100 api
```

## Development Configuration

### Hot Reload

```yaml
services:
  api:
    volumes:
      - ./src:/app/src  # Mount source for hot reload
    environment:
      - DEBUG=true
      - RELOAD=true
```

### Database Migrations

```bash
# Run migrations
docker-compose exec api alembic upgrade head

# Create migration
docker-compose exec api alembic revision --autogenerate -m "description"
```

## Production Configuration

### Production Overrides

```yaml
# docker-compose.prod.yml
version: '3.8'

services:
  api:
    restart: always
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G
    environment:
      - DATABASE_URL=${DATABASE_URL}
      - SECRET_KEY=${SECRET_KEY}
```

### Use Production Config

```bash
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
```

## Related Documentation

- [Docker Setup](./03-docker-setup) - Docker setup guide
- [Local Development](./02-local-development) - Local setup
