Feature: 006-docker-wasm-examples
Purpose: Docker containerization for KalamDB backend with CLI included
This directory contains Docker configurations for deploying KalamDB in containerized environments.
docker/
└── backend/
├── Dockerfile # Multi-stage build for kalamdb-server + kalam-cli
├── docker-compose.yml # Docker Compose configuration
├── build-backend.sh # Build script with verification
└── .env.example # Example environment variables (create as .env)
cd docker/backend
./build-backend.shThis creates kalamdb:latest with both server and CLI binaries.
docker-compose up -ddocker exec -it kalamdb kalam-cli user create --name "myuser" --role "user"Save the API key - you'll need it for authentication!
# Health check
curl http://localhost:8080/health
# Query with API key
curl -X POST http://localhost:8080/sql \
-H "Content-Type: application/json" \
-H "X-API-KEY: <your-api-key-here>" \
-d '{"query": "SELECT 1"}'./build-backend.sh --tag myregistry.com/kalamdb:v1.0.0./build-backend.sh --no-cache./build-backend.sh --tag myregistry.com/kalamdb:v1.0.0 --pushCreate a .env file in docker/backend/ to override defaults:
# Server configuration
KALAMDB_SERVER_PORT=8080
KALAMDB_SERVER_HOST=0.0.0.0
# Data directory (inside container)
KALAMDB_DATA_DIR=/data
# Logging
KALAMDB_LOG_LEVEL=info
KALAMDB_LOG_FILE=/data/logs/kalamdb.log
KALAMDB_LOG_TO_CONSOLE=true
# Connection limits
KALAMDB_MAX_CONNECTIONS=100Supported log levels: debug, info, warn, error
# Inspect volume
docker volume inspect kalamdb_data
# Backup data
docker run --rm -v kalamdb_data:/data -v $(pwd):/backup alpine tar czf /backup/kalamdb-backup.tar.gz /data
# Restore data
docker run --rm -v kalamdb_data:/data -v $(pwd):/backup alpine tar xzf /backup/kalamdb-backup.tar.gz -C /Edit docker-compose.yml:
volumes:
kalamdb_data:
driver: local
driver_opts:
type: none
o: bind
device: /path/to/host/data # Your custom pathdocker exec -it kalamdb kalam-clidocker exec kalamdb kalam-cli exec "SELECT * FROM system.users"# Copy file into container
docker cp schema.sql kalamdb:/tmp/schema.sql
# Execute
docker exec kalamdb kalam-cli load /tmp/schema.sqlUse Docker Swarm or Kubernetes for multi-node deployments:
# Docker Swarm example
docker swarm init
docker stack deploy -c docker-compose.yml kalamdb-stackMount certificates and update environment:
volumes:
- ./certs:/etc/kalamdb/certs:ro
environment:
KALAMDB_TLS_CERT: /etc/kalamdb/certs/server.crt
KALAMDB_TLS_KEY: /etc/kalamdb/certs/server.keyservices:
kalamdb:
deploy:
resources:
limits:
cpus: '2'
memory: 4G
reservations:
cpus: '1'
memory: 2G# Check logs
docker-compose logs kalamdb
# Common issues:
# - Port 8080 already in use
# - Volume permission errors
# - Config file errors# Verify volume exists
docker volume ls | grep kalamdb_data
# Check mount points
docker inspect kalamdb | grep -A 10 "Mounts"# Check resource usage
docker stats kalamdb
# Increase resources in docker-compose.yml (see Production Deployment)# List users (requires localhost or API key)
docker exec kalamdb kalam-cli exec "SELECT user_id, username, role FROM system.users"
# Create new user
docker exec kalamdb kalam-cli user create --name "newuser" --role "user"If you need to modify the build:
- Copy
DockerfiletoDockerfile.custom - Make your changes
- Build:
docker build -f Dockerfile.custom -t kalamdb:custom ../../
Run with debug logging:
docker-compose up -d
docker-compose exec kalamdb kalam-cli exec "UPDATE system.config SET log_level='debug'"
docker-compose restartEdit docker-compose.yml:
healthcheck:
test: ["CMD", "/usr/local/bin/kalam-cli", "exec", "SELECT COUNT(*) FROM system.users"]
interval: 10s
timeout: 5s
start_period: 30s
retries: 5For issues and questions:
- GitHub Issues: https://github.com/yourusername/KalamDB/issues
- Documentation: https://kalamdb.dev/docs