Self-Host OpenClaw with Docker
Docker is the most portable way to run OpenClaw on any machine. Whether you are on a laptop, a VPS, or a bare-metal server, Docker Compose gives you a reproducible single-command setup with persistent storage and sensible defaults. This guide covers installation, configuration, networking, and day-to-day operations.
Quick Path
For developers with Docker already installed:
- Clone the OpenClaw repository:
git clone https://github.com/openclaw/openclaw.git && cd openclaw - Copy the example environment file:
cp .env.example .env - Edit
.envand setANTHROPIC_API_KEYandOPENCLAW_GATEWAY_TOKEN - Run
docker compose up -d --build - Open
http://localhost:18789and authenticate with your gateway token
Prerequisites
- Docker Engine 20.10+ and Docker Compose v2 (included with Docker Desktop on macOS and Windows, or installed separately on Linux)
- An API key from your LLM provider (Anthropic, OpenAI, or OpenRouter)
- A terminal and a text editor
Install Docker
If Docker is not installed yet:
Project Setup
Clone the Repository
Create the Environment File
Copy the example and fill in your values:
Edit .env with the following variables:
Generate a strong gateway token:
Copy the output into the OPENCLAW_GATEWAY_TOKEN field in your .env file.
Docker Compose Configuration
The docker-compose.yml file defines the complete service:
Key details:
- Port binding:
127.0.0.1:18789:18789restricts access to localhost only. This is intentional for security. - Volumes: Named volumes (
openclaw-configandopenclaw-workspace) persist data across container restarts and rebuilds. - Restart policy:
unless-stoppedensures the service comes back after a crash or system reboot (as long as Docker starts automatically). - Health check: Polls
/healthevery 30 seconds so Docker can report the container's status and restart it if unhealthy.
Build and Launch
Build the image and start the service in detached mode:
Watch the logs to confirm a successful start:
You should see output indicating the gateway is listening:
Verify the container is healthy:
The STATUS column should show Up with (healthy) after the start period.
Accessing OpenClaw
Local Access
Open your browser and navigate to:
Authenticate with the OPENCLAW_GATEWAY_TOKEN you set in the .env file.
Remote Access via SSH Tunnel
If OpenClaw is running on a remote server, create an SSH tunnel instead of exposing the port publicly:
Then open http://localhost:18789 on your local machine. The traffic is encrypted through the SSH connection.
Remote Access via Tailscale
For persistent remote access without port forwarding, install Tailscale on both your local machine and the server:
Then access OpenClaw at http://your-server-tailscale-ip:18789. Tailscale handles encryption and authentication through your tailnet.
State and Persistence
OpenClaw stores all state in the mounted volumes:
| Path | Contents | Volume |
|---|---|---|
~/.openclaw/openclaw.json | Runtime configuration | openclaw-config |
~/.openclaw/agents/ | Agent definitions and instructions | openclaw-config |
~/.openclaw/workspace/ | Project files and session data | openclaw-workspace |
These volumes survive container rebuilds. To back them up:
To restore from a backup:
Customizing the Configuration
Edit Runtime Config
To modify openclaw.json while the container is running:
Restart the container to pick up changes:
Edit Agent Instructions
Agent instruction files live in the agents/ directory inside the config volume:
Add Model Providers
Uncomment or add the relevant API key in your .env file:
Then restart the service:
Security Best Practices
- Keep the port binding on localhost. The default
127.0.0.1:18789:18789prevents anyone on your network from accessing the gateway. Change it only if you understand the implications. - Use SSH tunnels or Tailscale for remote access. Both encrypt traffic and authenticate users without exposing the gateway port to the public internet.
- Protect the
.envfile. Set restrictive permissions:chmod 600 .env. Never commit it to version control. - Generate a strong gateway token. Use
openssl rand -hex 32or a password manager. Avoid short or predictable tokens. - Run as a non-root user. The OpenClaw Dockerfile creates a
nodeuser. Do not override this withuser: rootin docker-compose.yml. - Keep Docker updated. Security patches for the Docker engine and container runtime are released regularly.
Troubleshooting
Container exits immediately
Check the logs for error messages:
Common causes:
- Missing or malformed
.envfile - Invalid API key format
- Port 18789 already in use (check with
lsof -i :18789)
Cannot connect to localhost:18789
Verify the container is running and healthy:
If the container is running but you cannot connect, check that the port mapping is correct and no firewall is blocking local connections.
Permission denied errors in the container
The container runs as the node user (UID 1000). If the mounted volumes were created by root, the container cannot write to them. Fix permissions:
Builds are slow
Docker layer caching speeds up subsequent builds. If the cache is being invalidated unnecessarily, check that your .dockerignore excludes large directories like node_modules/, .git/, and test fixtures.
Health check failing
The health check runs curl -f http://localhost:18789/health inside the container. If curl is not available in the image, replace the health check with a TCP check:
Updating OpenClaw
Pull the latest changes and rebuild:
The named volumes are not affected by the rebuild. Your configuration, agent instructions, and workspace data remain intact.
To update without rebuilding from source (using a pre-built image):