> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch08-regional-platforms-and-deployment/8.3-docker-and-production-configuration.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 8.3 Docker Deployment and Production Configuration

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~182,000 tokens, Output \~9,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

## 8.3.1 Docker Compose Deployment

OpenClaw ships a `docker-compose.yml` and a `docker-setup.sh` in the repository.

### Minimal compose file

```yaml
services:
  openclaw:
    image: ghcr.io/openclaw/openclaw:latest
    restart: unless-stopped
    ports:
      - "127.0.0.1:18789:18789"    # note: bound to loopback on the host
    volumes:
      - ./openclaw-state:/root/.openclaw
      - ./openclaw-workspace:/root/openclaw-workspace
    environment:
      - OPENCLAW_GATEWAY_TOKEN=${OPENCLAW_GATEWAY_TOKEN}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
```

**Note the port binding: `127.0.0.1:18789:18789`, not `18789:18789`.**

The difference matters enormously. Without the `127.0.0.1:` prefix, Docker publishes the port on all interfaces — **and it punches through your firewall rules**, because Docker manipulates iptables directly. A great many accidental exposures come from exactly this.

### Starting it

```bash
# Put your secrets in .env (and add .env to .gitignore)
cat > .env <<'EOF'
OPENCLAW_GATEWAY_TOKEN=...
ANTHROPIC_API_KEY=...
TELEGRAM_BOT_TOKEN=...
EOF

docker compose up -d
docker compose logs -f
```

### First-run setup

```bash
docker compose exec openclaw openclaw onboard --non-interactive --accept-risk \
  --telegram-token "$TELEGRAM_BOT_TOKEN" \
  --anthropic-api-key "$ANTHROPIC_API_KEY"
```

**Non-interactive onboarding requires `--accept-risk` explicitly.** That's deliberate: the wizard normally shows a security briefing you have to acknowledge, and skipping the interaction shouldn't skip the acknowledgement.

## 8.3.2 Environment Variables and Persistence

### What must be persisted

| Path           | Contents                                                   | Losing it means                                          |
| -------------- | ---------------------------------------------------------- | -------------------------------------------------------- |
| `~/.openclaw/` | Config, credentials, sessions, memory index, pairing store | **Everything** — re-pair every channel, lose all history |
| `<workspace>/` | `AGENTS.md`, `SOUL.md`, `MEMORY.md`, daily memory files    | **The agent's personality and memory**                   |

Both need volumes. The workspace especially — it's plain Markdown you'd want in git anyway (§32.5.3).

### Key environment variables

```bash
OPENCLAW_GATEWAY_TOKEN     # gateway auth
OPENCLAW_GATEWAY_PORT      # default 18789
OPENCLAW_CONFIG_PATH       # config file location
OPENCLAW_STATE_DIR         # state directory
OPENCLAW_PROFILE           # multi-instance isolation
```

**Prefer environment variables over baking secrets into the config file** — the same reasoning as §7.1.2, plus it keeps them out of the image and out of any config volume you might share.

### Browser support in a container

Chrome needs extra packages and a larger shared memory segment:

```yaml
services:
  openclaw:
    shm_size: '2gb'          # Chrome crashes with the 64MB default
    # ... rest as above
```

**The `shm_size` line is required if you use the browser tool.** Docker's default `/dev/shm` is 64 MB, and Chrome will crash in ways that look mysterious.

### Sandboxing inside Docker

If you want `agents.defaults.sandbox.mode` to work, the container needs access to a Docker daemon (docker-in-docker or a mounted socket). **Mounting the host's Docker socket effectively gives the container host root** — think carefully about whether the sandbox is worth that trade in a containerized deployment.

## 8.3.3 A Production Checklist

Work through this before considering a deployment done.

### Network

* [ ] Port bound to `127.0.0.1`, not `0.0.0.0`
* [ ] `gateway.bind` is `loopback` or `tailnet`
* [ ] If anything is publicly reachable: `auth.mode` is `password`, and the token is long
* [ ] A reverse proxy (if used) forwards WebSocket upgrades and has a long `proxy_read_timeout`
* [ ] `trustedProxies` is configured if behind a proxy

### Credentials

* [ ] No plaintext keys in the config file — `openclaw secrets audit` returns clean
* [ ] `hooks.token` differs from the gateway token
* [ ] `.env` is in `.gitignore`
* [ ] The workspace git repo (if any) doesn't contain credentials

### Access control

* [ ] `dmPolicy` is `pairing` or `allowlist`, not `open`
* [ ] `allowFrom` uses stable IDs, not display names
* [ ] `groupPolicy` is `allowlist`
* [ ] `plugins.allow` is set explicitly

### Execution safety

* [ ] `security` is `allowlist`, not `full`
* [ ] `ask` is `on-miss` or `always`
* [ ] Sandbox enabled (`non-main`) if the agent processes external content
* [ ] `allowUnsafeExternalContent` is `false` everywhere

### Operations

* [ ] Persistent volumes for state and workspace
* [ ] `restart: unless-stopped` or an equivalent supervisor
* [ ] Log rotation configured
* [ ] A backup of `~/.openclaw/` and the workspace
* [ ] `openclaw doctor` runs clean
* [ ] **`openclaw security audit` runs clean**

> **Run `security audit` as the final step and take its severity ratings seriously.** They're context-dependent (§32.6.4) — the same finding is a warning on an isolated instance and critical on one with public channels attached. If it says critical, it's assessed your actual exposure.

### Costs

* [ ] Cheap models assigned to cron jobs and heartbeat
* [ ] Tool profile trimmed if you don't need the full set
* [ ] `openclaw usage cost` checked after a few days of real traffic

***

## Section Summary

1. **Bind the published port to `127.0.0.1`, not all interfaces** — Docker manipulates iptables directly and **punches through your firewall**, which is the source of a great many accidental exposures.
2. **Non-interactive onboarding requires `--accept-risk`** — skipping the interaction shouldn't skip the security acknowledgement.
3. **Two volumes are mandatory**: `~/.openclaw/` (losing it means re-pairing everything and losing history) and the workspace (**the agent's personality and memory**).
4. **`shm_size: '2gb'` is required for the browser tool** — Docker's 64 MB default makes Chrome crash mysteriously.
5. **Mounting the Docker socket for sandboxing effectively gives the container host root** — weigh whether the sandbox is worth that in a containerized deployment.
6. **Work the production checklist**, covering network, credentials, access control, execution safety, operations, and cost.
7. **Finish with `openclaw security audit` and take its severities seriously** — they're rated against your actual exposure, not the check in the abstract.
