🦞 OpenClaw Bootcamp
DAY 12 / 16
🐳
OpenClaw Bootcamp · Day 12

Docker:
Containerize Your Agent

Everything so far has run on your local machine. For a real agent that runs twenty-four seven, you need isolation and reproducibility. Docker gives you both — a portable, sandboxed environment that works the same everywhere.

Containers Sandbox Modes Production Ready
🦞 OpenClaw Bootcamp
DAY 12 / 16
Where We Are & Where We’re Going

Day 12 Goals

Day 11 Checkpoint
  • Connected integrations to real-world services and APIs
  • Configured webhooks for inbound and outbound events
  • Set up search and browser capabilities for your agent
01
Understand why Docker matters for agent deployments — isolation, reproducibility, and security
02
Configure sandbox modes and Docker Compose for a containerized agent
03
Run your agent in a Docker container with production-grade security and monitoring
🦞 OpenClaw Bootcamp
DAY 12 / 16
The Case for Containers

Why Docker for OpenClaw

🔒

Isolation

Your agent can’t touch the host filesystem. Sandbox mode non-main runs non-main sessions in per-session Docker containers automatically.

📦

Reproducibility

Same image everywhere — dev, staging, production. Pre-built images available on GitHub Container Registry with version-specific tags. No “works on my machine” surprises.

🛡

Security Boundary

Containers provide a hard security boundary. Combined with gVisor for kernel isolation, your agent runs in a sandboxed environment with controlled access to resources.

Easy rollback — revert to any previous image tag instantly
Sandboxing built in — agents.defaults.sandbox.mode
🦞 OpenClaw Bootcamp
DAY 12 / 16
Getting Started

Docker Setup

Prerequisites

Install Docker Desktop or Docker Engine. Pre-built OpenClaw images are hosted at ghcr.io/openclaw/openclaw. Pull the latest image to get started.

# docker-compose.yml services: openclaw: image: ghcr.io/openclaw/openclaw:latest ports: - "18789:18789" volumes: - ~/.openclaw:/home/node/.openclaw - ./workspace:/workspace restart: unless-stopped
Key Volumes
  • ~/.openclaw — Config, credentials, agent state. Mount as volume to persist across restarts.
  • /workspace — Your agent’s workspace with SOUL.md, AGENTS.md, MEMORY.md, and all workspace files.
  • Port 18789 — The gateway port. Expose it so channels and clients can reach your agent.
Quick Start

Run docker compose up -d and your agent is running in a container. All your existing config in ~/.openclaw carries over seamlessly via the volume mount.

🦞 OpenClaw Bootcamp
DAY 12 / 16
Containment Levels

Sandbox Modes

agents.defaults.sandbox.mode
offNo sandboxing. All sessions run on the host.
non-mainNon-main sessions run in per-session Docker containers. Main agent runs on host.
allEvery session — including main — runs inside a Docker container.
sandbox.scope
sessionEach session gets its own isolated container.
agentAll sessions for an agent share one container.
sharedAll agents share a single container.
Workspace Access
noneSandbox only, no workspace mount. (Default)
roRead-only access to /agent
rwRead-write access to /workspace
gVisor Kernel Isolation

For maximum containment, enable gVisor — an application kernel that intercepts system calls and provides an additional isolation layer between the container and the host kernel.

🦞 OpenClaw Bootcamp
DAY 12 / 16
Full Configuration

Docker Compose Deep Dive

Volumes
  • workspace — Agent workspace with SOUL.md, AGENTS.md, skills, and all workspace files
  • credentials — API keys, auth tokens, and provider configs
  • sessions — Conversation history and session state for persistence across restarts
Environment Variables

Pass API keys via environment variables rather than baking them into the image. Use env_file: .env or inline environment: blocks in your compose file.

Networking & Health
  • Loopback default — bind to 127.0.0.1 unless remote access is needed
  • Tailscale — secure remote access without exposing ports publicly
  • Health checks — use Docker health checks to monitor gateway availability
  • Restart policiesunless-stopped for production
Container Customization

Use sandbox.docker.setupCommand to run custom setup scripts when sandbox containers start — install additional packages, configure tools, or set up environment-specific dependencies.

🦞 OpenClaw Bootcamp
DAY 12 / 16
Hardening

Security in Docker

Critical: Docker & UFW

Docker bypasses host UFW rules entirely. If you rely on UFW for firewall management, you must add explicit rules to the DOCKER-USER iptables chain to restrict container network access.

Container Hardening
  • Run container as non-root user
  • Config files with permissions 600
  • State directory with permissions 700
  • Gateway auth required for all connections
Network Restrictions
  • Bind to 127.0.0.1 — never 0.0.0.0 unless behind a reverse proxy
  • Use DOCKER-USER iptables chain for egress filtering
  • Restrict outbound to only required API endpoints
  • No privileged mode — drop all unnecessary capabilities
Defense in Depth

Docker isolation + sandbox mode + tool policies + gateway auth = four independent security layers. Each one can fail independently without compromising the whole system.

🦞 OpenClaw Bootcamp
DAY 12 / 16
Running for Real

Production Patterns

Auto-Start with systemd

Create a systemd service file that starts your Docker container on boot. Use Restart=always and RestartSec=10 for automatic recovery from crashes.

# /etc/systemd/system/openclaw.service [Service] Type=simple ExecStart=docker compose up ExecStop=docker compose down Restart=always
Backup Strategy

Your workspace is just Markdown files — back up with git or rsync. Version control your SOUL.md, AGENTS.md, and MEMORY.md. Daily notes are time-stamped files, easy to archive.

Monitoring
  • Gateway health checks via gateway.channelHealthCheckMinutes
  • Log rotation — configure Docker logging driver with max-size and max-file
  • Docker health check — HTTP ping to the gateway port for container-level monitoring
Update Strategy

Pull new image, restart the container. Your workspace and config persist in volumes, so updates are non-destructive. Tags include latest, main, and version-specific — docker compose pull && docker compose up -d

🦞 OpenClaw Bootcamp
DAY 12 / 16
Before Day 13

Day 12 Homework

  • 01

    Install Docker

    Install Docker Desktop (macOS/Windows) or Docker Engine (Linux). Verify with docker --version and docker compose version. Make sure the Docker daemon is running.

  • 02

    Create a docker-compose.yml

    Write a compose file that mounts your ~/.openclaw directory, your workspace, and exposes port 18789. Use restart: unless-stopped for resilience.

  • 03

    Run Your Agent in a Container

    Run docker compose up -d and verify your agent is reachable. Test it from your configured channels — Telegram, Discord, or the web interface. Confirm your existing config carries over.

  • 04

    Test Sandbox Mode

    Set agents.defaults.sandbox.mode: "non-main" in your config. Spawn a sub-agent and verify it runs in its own Docker container. Check that the sub-agent can’t access the host filesystem.

🦞 OpenClaw Bootcamp
DAY 12 / 16
🦞
Coming Up

Day 13: VPS Deploy
Run Your Agent 24/7 in the Cloud

Your agent runs in a container. Now it needs a home that never sleeps. On Day 13 we take everything from your local Docker setup and deploy it to a VPS — a cloud server that runs your agent around the clock, handles restarts, and stays online while your laptop sleeps.

VPS Setup Cloud Deploy 24/7 Uptime