Docker Deployment¶
Deploy dgbit using Docker and docker-compose.
Prerequisites¶
- Docker 20.10+
- Docker Compose 2.0+
- 2GB+ RAM available
Quick Start¶
# Clone repository
git clone https://github.com/cryptuon/dgbit.git
cd dgbit
# Configure environment
cp dgbit-api/.env.example dgbit-api/.env
nano dgbit-api/.env # Edit with your settings
# Start all services
docker-compose up -d
# Check status
docker-compose ps
Services¶
The docker-compose.yml defines these services:
| Service | Description | Port |
|---|---|---|
api |
FastAPI REST API | 8000 |
backtest-worker |
Background job processor | - |
ui |
Vue 3 frontend | 3000 |
data-service |
Market data provider | - |
Configuration¶
Environment Variables¶
Create a .env file or set environment variables:
# Required for live trading
BYBIT_API_KEY=your_api_key
BYBIT_API_SECRET=your_api_secret
BYBIT_TESTNET=true
# Application settings
ENVIRONMENT=production
LOG_LEVEL=INFO
docker-compose.yml¶
The shipped docker-compose.yml defines four services. api and backtest-worker start by default; ui and data-service are behind the full profile.
services:
api:
image: cryptuon/dgbit-api:latest
ports:
- "8000:8000"
environment:
- ENVIRONMENT=production
- LOG_LEVEL=INFO
- NNG_COMMAND_ADDRESS=ipc:///tmp/dgbit_cmd.ipc
- NNG_EVENT_ADDRESS=ipc:///tmp/dgbit_evt.ipc
- BYBIT_API_KEY=${BYBIT_API_KEY:-}
- BYBIT_API_SECRET=${BYBIT_API_SECRET:-}
- BYBIT_TESTNET=${BYBIT_TESTNET:-true}
volumes:
- dgbit-db:/app/db
- dgbit-reports:/app/reports
- dgbit-logs:/app/logs
- dgbit-ipc:/tmp
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/api/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
restart: unless-stopped
backtest-worker:
image: cryptuon/dgbit-api:latest
command: ["python", "-m", "dgbit_api.workers.backtest_runner"]
depends_on:
api:
condition: service_healthy
ui:
profiles: ["full"]
build: ./dgbit-ui
ports: ["3000:3000"]
data-service:
profiles: ["full"]
command: ["python", "-m", "dgbit_data.service"]
Refer to the root docker-compose.yml for the authoritative version.
Building Images¶
Build All Services¶
Build Specific Service¶
Build with No Cache¶
Running Services¶
Start All Services¶
Start Specific Services¶
Start with Full Stack¶
This includes the UI and data-service.
Viewing Logs¶
All Services¶
Specific Service¶
Last N Lines¶
Stopping Services¶
Stop All¶
Stop and Remove Volumes¶
Stop Specific Service¶
Scaling Workers¶
Scale the backtest worker for more throughput:
Volumes¶
Data persistence is handled through Docker volumes:
| Volume | Purpose |
|---|---|
dgbit-db |
SQLite database |
dgbit-reports |
Backtest HTML reports |
dgbit-logs |
Application logs |
dgbit-ipc |
NNG IPC sockets |
Backup Volumes¶
# Backup database
docker run --rm -v dgbit-db:/data -v $(pwd):/backup alpine \
tar cvf /backup/dgbit-db-backup.tar /data
# Restore
docker run --rm -v dgbit-db:/data -v $(pwd):/backup alpine \
tar xvf /backup/dgbit-db-backup.tar -C /
Health Checks¶
The API service includes health checks:
# Check container health
docker-compose ps
# Manual health check
curl http://localhost:8000/api/health
Troubleshooting¶
Container Won't Start¶
# Check logs
docker-compose logs api
# Check container status
docker-compose ps -a
# Inspect container
docker inspect dgbit-api
Port Already in Use¶
Out of Memory¶
# Check memory usage
docker stats
# Limit memory per container
# In docker-compose.yml:
services:
api:
deploy:
resources:
limits:
memory: 1G
Permissions Issues¶
# Fix volume permissions
docker-compose down
sudo chown -R $(id -u):$(id -g) ./data
docker-compose up -d
Production Recommendations¶
- Use secrets management - Don't put API keys in docker-compose.yml
- Enable TLS - Use a reverse proxy (nginx, traefik)
- Set resource limits - Prevent runaway containers
- Configure logging - Ship logs to central system
- Regular backups - Backup volumes regularly
Example Production docker-compose.yml¶
services:
api:
image: cryptuon/dgbit:0.1.0
restart: always
deploy:
resources:
limits:
cpus: '2'
memory: 2G
environment:
- ENVIRONMENT=production
- LOG_LEVEL=WARNING
secrets:
- bybit_api_key
- bybit_api_secret
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
secrets:
bybit_api_key:
external: true
bybit_api_secret:
external: true
Next Steps¶
- Production Guide - Full production setup
- Monitoring - Set up monitoring