Docker Deployment

KlawTrade includes a Dockerfile and docker-compose configuration for containerized deployment. Running in Docker is recommended for always-on setups where you want the engine to restart automatically after reboots or crashes.

Dockerfile

The included Dockerfile uses a Python 3.12 slim base image, installs dependencies, and sets the entry point to the KlawTrade CLI.

FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8080

CMD ["klawtrade", "start"]

You can build the image manually if you prefer not to use docker-compose:

docker build -t klawtrade .
docker run -d --name klawtrade -p 8080:8080 --env-file .env klawtrade

Docker Compose

The docker-compose.yml file provides a ready-to-use configuration with persistent volumes, automatic restarts, and environment variable loading.

version: "3.8"

services:
  klawtrade:
    build: .
    container_name: klawtrade
    restart: unless-stopped
    ports:
      - "8080:8080"
    env_file:
      - .env
    volumes:
      - ./config:/app/config
      - klawtrade-data:/app/data
      - klawtrade-logs:/app/logs

volumes:
  klawtrade-data:
  klawtrade-logs:

Start the container with:

docker compose up -d

To view logs in real time:

docker compose logs -f klawtrade

Environment Variables

The container reads credentials from the .env file via the env_file directive. Make sure this file exists in the same directory as your docker-compose.yml.

ALPACA_API_KEY=your_api_key_here
ALPACA_SECRET_KEY=your_secret_key_here

Alternatively, you can pass environment variables directly in the docker-compose file or through your orchestrator's secret management system.

Persistent Volumes

The compose configuration mounts three paths to ensure data survives container restarts:

VolumeContainer PathPurpose
./config/app/configBind mount for settings.yaml so you can edit config without rebuilding the image.
klawtrade-data/app/dataNamed volume for trade history, portfolio snapshots, and strategy state.
klawtrade-logs/app/logsNamed volume for application logs. Persists across container restarts for debugging.