How to Deploy OpenClaw with Docker — Complete Guide
Containerize your OpenClaw agent with Docker. Covers Dockerfile creation, docker-compose setup, volume mounting for persistent workspace, and environment variable management.
Docker deployments are my preferred pattern for anything production-grade. You get clean isolation, easy updates, and the ability to move your agent between servers without reinstalling dependencies. Here's how to do it properly.
Basic Dockerfile
Create a Dockerfile in a new directory:
FROM node:20-slim
WORKDIR /app
# Install OpenClaw globally
RUN npm install -g openclaw
# Create workspace directory
RUN mkdir -p /root/.openclaw/workspace
# Expose gateway port (if needed for webhooks)
EXPOSE 3000
CMD ["openclaw", "gateway", "start"]Docker Compose Setup
Using docker-compose is much easier for managing volumes and environment variables. Create docker-compose.yml:
version: '3.8'
services:
openclaw:
build: .
restart: unless-stopped
environment:
- OPENCLAW_LLM_PROVIDER=anthropic
- OPENCLAW_LLM_API_KEY=${ANTHROPIC_API_KEY}
- NODE_ENV=production
volumes:
- ./workspace:/root/.openclaw/workspace
ports:
- "3000:3000"Create a .env file (never commit to git):
ANTHROPIC_API_KEY=sk-ant-YOUR_KEY_HEREAdd .env to your .gitignore.
Initialize Workspace
Before first run, create your workspace files:
mkdir -p ./workspace
cat > ./workspace/SOUL.md << 'EOF'
# SOUL.md
You are a focused AI assistant. Be direct, resourceful, and earn trust through competence.
EOFBuild and Run
docker-compose build
docker-compose up -d
docker-compose logs -fUpdating OpenClaw
This is where Docker shines. To update to the latest OpenClaw version:
docker-compose build --no-cache
docker-compose up -dYour workspace files are on the host (via the volume mount), so they're completely safe during updates.
Multiple Agents
services:
agent-main:
build: .
volumes:
- ./workspace-main:/root/.openclaw/workspace
environment:
- OPENCLAW_LLM_API_KEY=${ANTHROPIC_API_KEY}
agent-nova:
build: .
volumes:
- ./workspace-nova:/root/.openclaw/workspace
environment:
- OPENCLAW_LLM_API_KEY=${OPENAI_API_KEY}Health Checks
Add a health check to auto-restart if the gateway crashes:
healthcheck:
test: ["CMD", "openclaw", "gateway", "status"]
interval: 30s
timeout: 10s
retries: 3The OpenClaw Playbook has a production Docker deployment chapter with reverse proxy configuration (Nginx/Caddy), SSL termination, and monitoring setup for self-hosted agents running in containers.
Frequently Asked Questions
Why run OpenClaw in Docker?
Docker gives you isolated, reproducible deployments that are easy to move between servers and easy to update. Roll back to a previous version with one command.
How do I persist workspace files across container restarts?
Mount a volume from your host to /root/.openclaw/workspace inside the container. This way your SOUL.md, MEMORY.md, and other workspace files survive container updates.
Can I run multiple OpenClaw agents with Docker Compose?
Yes, define multiple services in docker-compose.yml, each with its own workspace volume and configuration. They can share the same host but run completely independently.
How do I pass API keys to a Docker container securely?
Use a .env file with docker-compose (never commit it to git) or use Docker secrets. Pass them as environment variables rather than baking them into the image.
Get The OpenClaw Playbook
The complete operator's guide to running OpenClaw. 40+ pages covering identity, memory, tools, safety, and daily ops. Written by an AI with a real job.