You have a server that already runs a few containers and you want OpenClaw (openclaw.ai) to be one of them — same supervision pattern (docker daemon + restart policy), same backup story (named volumes), same observability (docker logs, Prometheus exporters). The OpenClaw runtime is a Node.js daemon; it containerizes cleanly. The official base image is node:24-bookworm-slim, the persistence boundary is the home directory of the in-container node user, and the only port that needs to be exposed is 18789. This walks the full Dockerfile, the docker-compose, and the verification.
Scenario
A Linux host running Docker Engine 24+ or Docker Desktop. You want OpenClaw containerized — easy upgrade, isolated dependency tree, and a clean blast radius if a custom skill misbehaves. The host has at least 2 GB RAM free for the container, a 5 GB volume for persistent state, and network access to your LLM provider (Anthropic, OpenAI, or a local Ollama on the LAN).
Outcome and prereqs
When this is done you’ll have:
- A custom Docker image (or the bundled OpenClaw image) running the gateway as the
nodeuser inside the container. - A named Docker volume
openclaw_homemounted at/home/nodeinside the container, holding.openclaw/, workspace, memory, and config. - The gateway reachable on
127.0.0.1:18789from the host. docker composemanaging lifecycle, restart policyunless-stopped.- Logs available via
docker logs openclaw -f.
Prereqs:
- Docker Engine 24+ (
docker --version) and Compose v2 (docker compose version). - 5 GB free disk for the image + volume.
- An LLM provider API key, or a local Ollama/LM Studio on the host reachable at
host.docker.internal. - A non-root user in the
dockergroup, or sudo for the docker commands.
Time and resource footprint
20 minutes attended for the first build. Steady-state, the container sits around 300 MB RAM with the gateway plus its Node dependencies. CPU is essentially zero when idle.
Step 1 — Project layout
Create a directory:
mkdir -p ~/openclaw-docker
cd ~/openclaw-docker
You will end up with two files: Dockerfile and docker-compose.yml. The volume is named, so there is no ./data directory in the project — state lives in a Docker volume that survives docker compose down.
Step 2 — Dockerfile
Write ~/openclaw-docker/Dockerfile:
# OpenClaw — runs the gateway as the unprivileged node user
FROM node:24-bookworm-slim
# tini reaps zombies and forwards signals cleanly to the Node process
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl tini \
&& rm -rf /var/lib/apt/lists/*
# Install OpenClaw globally as root, so /usr/local/bin/openclaw is on PATH
RUN npm install -g openclaw@latest \
&& npm cache clean --force
# Persist everything OpenClaw writes under /home/node — that's where ~/.openclaw lives
USER node
WORKDIR /home/node
# Environment: OpenClaw reads these on every start
ENV HOME=/home/node \
OPENCLAW_HOME=/home/node/.openclaw \
OPENCLAW_GATEWAY_BIND=0.0.0.0 \
OPENCLAW_GATEWAY_PORT=18789 \
NODE_COMPILE_CACHE=/home/node/.cache/openclaw-compile-cache
# Health endpoint — Docker uses this to know the container is alive
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD curl -fsS http://127.0.0.1:18789/healthz || exit 1
EXPOSE 18789
# tini as PID 1 so SIGTERM forwards cleanly to the Node child
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["openclaw", "gateway", "--port", "18789"]
A few notes:
- The base image is
node:24-bookworm-slim, which matches the OpenClaw docs’ guidance for the bundled image. It is small, has glibc (some npm packages do not have musl prebuilds), and is on a maintained Debian release. tinias PID 1 is the standard Node-in-Docker pattern. Without it,docker stopsends SIGTERM to a Node process that does not always forward signals to its children, and you get 10-second timeouts on every shutdown. ThetiniREADME on GitHub has the rationale.OPENCLAW_GATEWAY_BIND=0.0.0.0is correct inside the container. The container’s networking is its own; binding to all interfaces inside the container does not expose the gateway on the host’s external NIC unless you publish the port that way. Thedocker-compose.ymlbelow publishes it on127.0.0.1:18789on the host, which is the safe default.OPENCLAW_HOME=/home/node/.openclawis the explicit override. Some skills assume$HOMEresolves to the persistence boundary; setting bothHOMEandOPENCLAW_HOMEremoves the ambiguity.
Build:
docker build -t openclaw:local .
The first build takes 2-3 minutes; subsequent builds with cached layers are seconds.
Step 3 — docker-compose.yml
Write ~/openclaw-docker/docker-compose.yml:
services:
openclaw:
image: openclaw:local
container_name: openclaw
restart: unless-stopped
# Publish only on loopback. Remote access goes through Tailscale, not 0.0.0.0.
ports:
- "127.0.0.1:18789:18789"
environment:
# Provider keys — never commit these. Use an .env file or a secrets manager.
ANTHROPIC_API_KEY: "${ANTHROPIC_API_KEY:-}"
OPENAI_API_KEY: "${OPENAI_API_KEY:-}"
# Useful if you run a local LLM on the host (Ollama, LM Studio):
# OLLAMA_BASE_URL: "http://host.docker.internal:11434"
extra_hosts:
# So the container can reach services on the host by name
- "host.docker.internal:host-gateway"
volumes:
- openclaw_home:/home/node
# Resource ceilings — same idea as MemoryMax= on systemd
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 512M
# Log rotation: 10 MB per file, keep 5 files
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
# Strip Linux capabilities the agent does not need
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
volumes:
openclaw_home:
name: openclaw_home
Then a .env file in the same directory (mode 600, not in git):
cat > ~/openclaw-docker/.env <<'ENV'
ANTHROPIC_API_KEY=sk-ant-replace-me
ENV
chmod 600 ~/openclaw-docker/.env
Compose loads .env by default for variable substitution. The keys end up as environment variables inside the container, not on disk in the image. The volumes: section declares a named volume that Docker manages outside the project directory — docker volume inspect openclaw_home shows its on-disk location.
Step 4 — Onboard once, then bring it up
The OpenClaw onboarding flow is interactive. Run it once inside the container before bringing the service up under compose:
docker compose run --rm openclaw openclaw onboard
Pick your default model, paste the API key, accept the daemon install (the container itself is the daemon supervisor here, but onboarding writes the right openclaw.json fields). Onboarding writes into /home/node/.openclaw/, which is the named volume — the state survives the throwaway --rm container.
Then bring the service up:
docker compose up -d
docker compose ps
docker compose logs -f openclaw
docker compose ps should show running (healthy) within 30 seconds. If it says unhealthy, look at the logs — almost always a missing or wrong API key.
Step 5 — Reach the gateway
From the host:
curl -fsS http://127.0.0.1:18789/healthz
# {"status":"ok"}
ss -lntp 'sport = :18789'
# LISTEN ... 127.0.0.1:18789 ...
openclaw doctor against the containerized gateway is a bit different — you have to invoke it inside the container, because doctor reads the local config:
docker compose exec openclaw openclaw doctor
To talk to the agent from the host without entering the container:
docker compose exec openclaw openclaw agent --message "What container am I running in?" --thinking high
The agent should run cat /etc/os-release (it sees Debian Bookworm) and cat /proc/1/cgroup (it sees the docker cgroup path).
Step 6 — Local LLMs via host.docker.internal
If you run Ollama or LM Studio on the host (not in a container), the container reaches them via host.docker.internal, which the extra_hosts block above maps to the actual host gateway. In openclaw.json (inside the volume; edit via docker compose exec openclaw vi /home/node/.openclaw/openclaw.json):
{
"agent": {
"model": "ollama/llama3.1:70b"
},
"providers": {
"ollama": {
"baseUrl": "http://host.docker.internal:11434"
}
}
}
docker compose restart openclaw after edits. The OpenClaw docs are explicit that host.docker.internal is the right path for local model providers when OpenClaw itself is containerized.
Step 7 — Upgrades
Two paths.
Rebuild from the npm package (matches your Dockerfile):
cd ~/openclaw-docker
docker build --no-cache -t openclaw:local .
docker compose up -d
Pull the bundled image (if you choose to use the OpenClaw-published image instead of your own Dockerfile):
# In docker-compose.yml, replace `image: openclaw:local` with:
# image: ghcr.io/openclaw/openclaw:latest
Then:
docker compose pull
docker compose up -d
Either way, the named volume openclaw_home is untouched, so your config, memory, skills, and channel pairings survive.
Verification
docker compose ps # running (healthy)
docker compose exec openclaw openclaw doctor # green checks
curl -fsS http://127.0.0.1:18789/healthz # ok
docker stats openclaw --no-stream # RAM, CPU within limits
docker compose logs --tail=50 openclaw # no recent errors
The full happy-path check is healthy + green doctor + a real round-trip:
docker compose exec openclaw \
openclaw agent --message "List the largest files under my workspace" \
--thinking high
Rollback
docker compose down # stops the container, keeps volume
docker compose down -v # stops and DELETES the named volume — destructive
docker image rm openclaw:local # removes the image
Before down -v, back up the volume:
docker run --rm -v openclaw_home:/data -v "$(pwd)":/backup alpine \
tar czf /backup/openclaw_home.$(date +%F).tar.gz -C /data .
That tarball contains the entire stateful surface and can be restored into a fresh volume.
Troubleshooting
Container starts, becomes unhealthy, healthcheck fails. docker compose logs openclaw first. Almost always either a missing ANTHROPIC_API_KEY/OPENAI_API_KEY in .env or a network egress block reaching the provider. Test with docker compose exec openclaw curl -fsS https://api.anthropic.com.
Permission denied writing to /home/node/.openclaw. The named volume was created with bad ownership. docker compose down, docker volume rm openclaw_home, docker compose up -d and rerun onboarding.
Onboarding asks to bind a TTY but errors out. Use docker compose run --rm (it gives you an interactive TTY) and not docker compose exec for the first onboard. exec requires the service to already be running.
Local Ollama unreachable from container. Confirm extra_hosts is set, then test inside the container: docker compose exec openclaw curl -fsS http://host.docker.internal:11434/api/tags. On Linux hosts, host.docker.internal requires the host-gateway mapping shown above (Docker Desktop has it by default).
Container restarts every 10 seconds. docker compose logs openclaw --tail=200 shows the crash. tini as PID 1 ensures the exit code propagates; you should see a real error message before the SIGTERM.
Volume balloons in size. logs/, browser-automation cache, and session JSONL files are the usual suspects. docker compose exec openclaw du -sh /home/node/.openclaw/* shows the breakdown. Trim with the OpenClaw retention settings or by truncating logs/.
SIGTERM hangs for 10 seconds on every restart. You skipped tini and Node is not forwarding signals to children. Add init: true to the compose service (Compose v2 has a built-in init), or restore the tini ENTRYPOINT.
Production-readiness
For OpenClaw in Docker on a host you depend on:
- Image pinned to a specific version tag in production, not
:latest. Tag your own builds. - The
openclaw_homevolume in your backup target —docker run --rm -v openclaw_home:/data ...is the canonical export, scriptable into your existing backup tool. - A
docker compose pull && docker compose up -dweekly maintenance window with a manualopenclaw doctorafter. - Resource limits (
memory: 2Gabove) tuned to the host. Without them, a runaway skill can consume the host’s RAM. cap_drop: ALLandno-new-privileges:trueare non-negotiable. The agent has no business with raw caps.- Egress firewall rules confirming the container can reach
api.anthropic.com/api.openai.com/ your Ollama host, and nothing else worth worrying about.
For organizations that want OpenClaw managed under Docker as part of a broader environment-management contract, talk to a senior operator at Stack Harbor about your self-hosted OpenClaw setup.
Related
- Self-hosting OpenClaw on Linux desktop (Ubuntu and Fedora) — the bare-metal alternative to a container.
Sources
- OpenClaw home page —
https://openclaw.ai. - OpenClaw README and Docker page —
https://github.com/openclaw/openclawandhttps://docs.openclaw.ai/install/docker. - Docker Compose reference —
https://docs.docker.com/compose/compose-file/. - Node.js Docker best practices —
https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md. - tini —
https://github.com/krallin/tini. host.docker.internaldocumentation —https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host.
Last verified on OpenClaw current (May 2026).