# Docker Services

Set up a local Docker services cluster for your PA to use. Common services include PostgreSQL, Redis, and other infrastructure your projects depend on.


## What it does

Creates a Docker Compose configuration that runs local service containers, accessible to your PA and your applications. Services are isolated, reproducible, and easy to tear down.


## Prerequisites

- Docker Desktop (macOS/Windows) or Docker Engine (Linux)
- Docker Compose v2 (usually included with Docker Desktop)
- Sufficient disk space for container images


## Steps

### 1. Create the compose file

Create `docker/docker-compose.yml` in your repo root:

```yaml
version: "3.8"

services:
  postgres:
    image: postgres:16-alpine
    container_name: dave-postgres
    environment:
      POSTGRES_USER: dave
      POSTGRES_PASSWORD: localdev
      POSTGRES_DB: dave
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U dave"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: dave-redis
    ports:
      - "6379:6379"
    volumes:
      - redisdata:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  pgdata:
  redisdata:
```

### 2. Start the services

```bash
cd docker
docker compose up -d
```

Verify they are running:

```bash
docker compose ps
```

You should see both containers with status "healthy".

### 3. Test connectivity

PostgreSQL:

```bash
docker exec -it dave-postgres psql -U dave -c "SELECT version();"
```

Redis:

```bash
docker exec -it dave-redis redis-cli ping
# Should output: PONG
```

### 4. Store credentials in the vault

```bash
node core/tools/secrets/bin/secrets set POSTGRES_URL "postgresql://dave:localdev@localhost:5432/dave"
node core/tools/secrets/bin/secrets set REDIS_URL "redis://localhost:6379"
```

### 5. Configure your PA to use the services

Your PA can now reference these services by their connection URLs. When your PA needs database access for a project, it will use the credentials from the vault.


## Managing services

Start all services:

```bash
cd docker && docker compose up -d
```

Stop all services (preserves data):

```bash
cd docker && docker compose stop
```

Remove all services and data:

```bash
cd docker && docker compose down -v
```

View logs:

```bash
cd docker && docker compose logs -f
```


## Adding more services

Add new service blocks to `docker-compose.yml`. Common additions:

**Elasticsearch:**
```yaml
  elasticsearch:
    image: elasticsearch:8.12.0
    container_name: dave-elasticsearch
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
    ports:
      - "9200:9200"
```

**MinIO (S3-compatible storage):**
```yaml
  minio:
    image: minio/minio
    container_name: dave-minio
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    ports:
      - "9000:9000"
      - "9001:9001"
```


## Notes

- Default credentials are for local development only -- never use them in production
- Named volumes (`pgdata`, `redisdata`) persist data across container restarts
- Use `docker compose down -v` to completely reset all data
- Port conflicts: if a port is already in use, change the host port mapping (e.g. `5433:5432`)
