Deploy Krab using Docker for easy containerized deployment with persistent data and optional services.
- Docker Engine 20.10+
- Docker Compose 2.0+
- 1GB RAM minimum (2GB recommended)
- 2GB storage minimum
-
Clone the repository:
git clone https://github.com/yourusername/krab.git cd krab -
Configure environment:
cp .env.example .env # Edit .env with your API keys -
Build and run:
docker-compose up -d
-
Check status:
docker-compose logs krab curl http://localhost:3000/health
-
Access Control Panel: Open http://localhost:3000/control
Create a .env file in the project root:
# Required: Choose at least one LLM provider
GEMINI_API_KEY=your_gemini_api_key
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
# Optional: Messaging channels
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
DISCORD_BOT_TOKEN=your_discord_bot_token
LINE_CHANNEL_ACCESS_TOKEN=your_line_access_token
LINE_CHANNEL_SECRET=your_line_secret
# Krab configuration
KRAB_DEFAULT_MODEL=anthropic/claude-sonnet-4-5
KRAB_DEBUG=false
# Optional: Database (if using PostgreSQL)
POSTGRES_PASSWORD=your_secure_password
DATABASE_URL=postgresql://krab:password@postgres:5432/krabThe Docker setup creates persistent volumes for:
./data:/app/data- SQLite databases, session data./config:/app/config- Configuration files (optional)
Main Krab application with:
- Gateway server (port 18789)
- Webhook server (port 3000)
- Control panel UI
- Health checks
Production-ready database:
docker-compose --profile postgres up -dCaching and session storage:
docker-compose --profile redis up -dReverse proxy with SSL:
docker-compose --profile proxy up -dFor production optimization:
FROM node:22-alpine AS builder
# ... build stage ...
FROM node:22-alpine AS production
# ... production stage ...
# Add custom optimizations
RUN apk add --no-cache sqlite
ENV NODE_ENV=productionFor zero-downtime deployments:
# Build new image
docker-compose build --no-cache
# Deploy with blue-green
docker-compose up -d --scale krab=2
docker-compose up -d --scale krab=1Adjust resources in docker-compose.yml:
services:
krab:
deploy:
resources:
limits:
cpus: '2.0'
memory: 4G
reservations:
cpus: '1.0'
memory: 2G# All services
docker-compose logs
# Specific service
docker-compose logs krab
# Follow logs
docker-compose logs -f krab# Check container health
docker-compose ps
# Manual health check
curl http://localhost:3000/health
curl http://localhost:3000/ready# Container stats
docker stats
# Specific container
docker stats krab_krab_1# Stop containers
docker-compose down
# Backup data directory
tar -czf backup-$(date +%Y%m%d).tar.gz ./data/
# Start containers
docker-compose up -d# Stop containers
docker-compose down
# Restore data
tar -xzf backup-20240101.tar.gz
# Start containers
docker-compose up -d# Check what's using ports
netstat -tulpn | grep :18789
netstat -tulpn | grep :3000
# Change ports in docker-compose.yml
ports:
- "18889:18789"
- "3001:3000"# Fix data directory permissions
sudo chown -R 1001:1001 ./data/# Increase Docker memory limit
# Docker Desktop: Preferences > Resources > MemoryEnable debug logging:
# Set environment variable
echo "KRAB_DEBUG=true" >> .env
# Restart containers
docker-compose restart krabservices:
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx-ssl.conf:/etc/nginx/nginx.conf
- ./ssl:/etc/ssl/certs
depends_on:
- krabFor high availability:
services:
krab:
deploy:
replicas: 3
restart_policy:
condition: on-failure
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx-lb.conf:/etc/nginx/nginx.conf- Store sensitive data in
.env(gitignored) - Use Docker secrets for production
- Rotate API keys regularly
- Use internal networks for database
- Restrict exposed ports
- Enable firewall rules
- Run as non-root user (UID 1001)
- Use minimal base images
- Regular security updates
# Pull latest changes
git pull
# Rebuild and restart
docker-compose down
docker-compose build --no-cache
docker-compose up -d
# Check logs
docker-compose logs -f krab# Stop and remove containers
docker-compose down
# Remove volumes (WARNING: destroys data)
docker-compose down -v
# Clean up images
docker system prune -a