Moltbot Docker Setup
Docker provides an optional way to run Moltbot in a container. This is useful for isolated environments, CI/CD, or if you prefer containerized deployments.
Note: Docker is optional. For most users, we recommend the macOS App or Linux systemd
TL;DR
# Clone the repo
git clone https://github.com/moltbot/moltbot.git
cd moltbot
# Build and run
docker-compose up -d
# Setup (first time)
docker exec -it moltbot pnpm moltbot setup
# Connect channels
docker exec -it moltbot pnpm moltbot channels login
# Health check
docker exec moltbot pnpm moltbot healthWhen to Use Docker
Docker is a good choice when you:
- Want complete isolation from the host system
- Need reproducible deployments across environments
- Are running in Kubernetes or similar orchestration
- Prefer containerized infrastructure
- Need to run e2e tests in CI/CD
For development with hot reload, see Gateway Development
Prerequisites
- Docker Engine 20.10+ (Install Docker)
- Docker Compose v2+ (included with Docker Desktop)
- Git
Quick Start with Docker Compose
1. Clone the Repository
git clone https://github.com/moltbot/moltbot.git
cd moltbot2. Configure Environment
Copy the example environment file:
cp .env.example .envEdit .env with your settings:
# AI Provider
AI_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-...
# Gateway
GATEWAY_PORT=18789
# Optional: Logging
LOG_LEVEL=info3. Start the Container
docker-compose up -d4. Run Initial Setup
docker exec -it moltbot pnpm moltbot setup5. Connect Channels
docker exec -it moltbot pnpm moltbot channels login6. Verify
docker exec moltbot pnpm moltbot healthDocker Compose Configuration
Here's the recommended docker-compose.yml:
version: '3.8'
services:
moltbot:
build: .
container_name: moltbot
restart: unless-stopped
ports:
- "18789:18789"
volumes:
# Persist config and credentials
- ~/.clawdbot:/root/.clawdbot
# Persist workspace
- ~/clawd:/root/clawd
# Optional: mount for development
# - ./src:/app/src
environment:
- NODE_ENV=production
- GATEWAY_PORT=18789
env_file:
- .envVolume Mounts
To persist data between container restarts:
| Host Path | Container Path | Purpose |
|---|---|---|
~/.clawdbot | /root/.clawdbot | Config and credentials |
~/clawd | /root/clawd | Workspace (skills, prompts) |
Important: Without volume mounts, you'll lose all configuration and credentials when the container is removed!
Building the Image
Using Docker Compose
docker-compose buildManual Build
docker build -t moltbot:latest .Multi-Platform Build
For ARM64 and AMD64:
docker buildx build --platform linux/amd64,linux/arm64 -t moltbot:latest .Running Without Compose
docker run -d \
--name moltbot \
--restart unless-stopped \
-p 18789:18789 \
-v ~/.clawdbot:/root/.clawdbot \
-v ~/clawd:/root/clawd \
--env-file .env \
moltbot:latestContainer Management
View Logs
# Follow logs
docker logs -f moltbot
# Last 100 lines
docker logs --tail 100 moltbotExecute Commands
# Interactive shell
docker exec -it moltbot sh
# Run moltbot CLI
docker exec moltbot pnpm moltbot health
docker exec -it moltbot pnpm moltbot channels loginRestart
docker-compose restart
# or
docker restart moltbotStop and Remove
docker-compose down
# or
docker stop moltbot && docker rm moltbotUpdating
With Docker Compose
# Pull latest code
git pull
# Rebuild and restart
docker-compose up -d --buildManual Update
# Stop container
docker stop moltbot
# Pull/build new image
docker build -t moltbot:latest .
# Remove old container
docker rm moltbot
# Start new container
docker run -d --name moltbot ... moltbot:latestHealth Checks
Add a health check to your docker-compose.yml:
services:
moltbot:
# ... other config
healthcheck:
test: ["CMD", "pnpm", "moltbot", "health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40sResource Limits
Constrain container resources:
services:
moltbot:
# ... other config
deploy:
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.5'
memory: 256MNetworking
Expose Only Locally
For security, bind only to localhost:
ports:
- "127.0.0.1:18789:18789"Custom Network
services:
moltbot:
networks:
- moltbot-net
networks:
moltbot-net:
driver: bridgeCommon Issues
Container Exits Immediately
docker logs moltbotCommon causes:
- Missing environment variables
- Invalid config file
- Port already in use on host
Permission Denied on Volumes
sudo chown -R $(id -u):$(id -g) ~/.clawdbot ~/clawdOr run as non-root (advanced):
services:
moltbot:
user: "1000:1000"Can't Connect to Gateway
docker port moltbot
# Should show: 18789/tcp -> 0.0.0.0:18789WhatsApp QR Code Not Displaying
Use interactive mode. The -it flags are required for QR code display.
docker exec -it moltbot pnpm moltbot channels login whatsappSecurity Considerations
- Never commit .env files with secrets
- Use Docker secrets for production
- Run as non-root user when possible
- Limit container capabilities
- Keep images updated