OpenClaw needs a persistent, always-on environment to stay connected to your messaging platforms and AI provider. Running it inside a Docker container on a VPS gives you isolated storage, automatic restarts on failure and a repeatable setup you can rebuild at any time.
This guide walks you through creating the directory structure, writing the environment and Compose files, completing first-run onboarding and keeping OpenClaw up to date. It also covers building from source if an official image is not available for your architecture.
Keeping all OpenClaw files in a single directory makes backups, upgrades and troubleshooting easier. Create the directory and move into it before writing any configuration files.
mkdir -p /opt/openclaw
cd /opt/openclaw
OpenClaw reads all sensitive credentials from a .env file rather than baking them into the Compose configuration. Create this file first and restrict its permissions so only root can read it.
/opt/openclaw/.env in your editor:nano /opt/openclaw/.env
# at the start.# AI Provider - uncomment one
ANTHROPIC_API_KEY=your_anthropic_api_key
# OPENAI_API_KEY=your_openai_api_key
# Messaging platform - uncomment whichever you are using
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
# DISCORD_BOT_TOKEN=your_discord_bot_token
# SLACK_BOT_TOKEN=your_slack_bot_token
# Timezone
TZ=Europe/London
chmod 600 /opt/openclaw/.env
The Compose file defines the container, tells Docker where to find your credentials and mounts a named volume so OpenClaw’s memory, skills and configuration survive container restarts and upgrades.
/opt/openclaw/docker-compose.yml:nano /opt/openclaw/docker-compose.yml
restart: unless-stopped policy means Docker restarts the container automatically after a crash or a VPS reboot, unless you explicitly stop it yourself.services:
openclaw:
image: ghcr.io/openclaw/openclaw:latest
container_name: openclaw
restart: unless-stopped
env_file:
- .env
volumes:
- openclaw_data:/home/node/.openclaw
environment:
- NODE_ENV=production
volumes:
openclaw_data:
driver: local
OpenClaw is an actively developed project. Check the OpenClaw GitHub repository for the current recommended image tag before deploying. If an official image is not available for your architecture, see the Building from source section below.
The first time OpenClaw runs, it requires an interactive onboarding step to configure your persona and connect your integrations. Start the container, then run onboarding inside it before leaving it to run in the background.
/opt/openclaw, bring the service up in detached mode:cd /opt/openclaw
docker compose up -d
docker compose exec openclaw openclaw onboard
docker compose restart openclaw
Ctrl+C to stop following:docker compose logs -f openclaw
OpenClaw is now running as a persistent background service. The named volume protects your data across restarts.
If an official image is not available for your architecture or the current version, you can build the image directly from the GitHub repository. This replaces the image: line in your Compose file with a local build.
src subdirectory inside your project folder:cd /opt/openclaw
git clone https://github.com/openclaw/openclaw.git src
/opt/openclaw/Dockerfile. It installs production dependencies and starts the compiled entry point:FROM node:20-alpine
WORKDIR /app
COPY src/ .
RUN npm install --production --no-fund --no-audit
RUN npm run build 2>/dev/null || true
EXPOSE 3000
CMD ["node", "dist/index.js"]
image: line with build: . so Docker Compose builds from your Dockerfile instead of pulling a remote image:services:
openclaw:
build: .
container_name: openclaw
restart: unless-stopped
env_file:
- .env
volumes:
- openclaw_data:/home/node/.openclaw
environment:
- NODE_ENV=production
volumes:
openclaw_data:
driver: local
--build flag forces Docker Compose to build the image before starting the container:docker compose up -d --build
Return to the onboarding step above to complete your first-run configuration.
The following commands cover the most common day-to-day tasks. Run them from /opt/openclaw unless noted otherwise.
# View live logs
docker compose logs -f openclaw
# Stop OpenClaw
docker compose down
# Restart
docker compose restart openclaw
# Open a shell inside the container
docker compose exec openclaw sh
# Run a one-off OpenClaw command
docker compose exec openclaw openclaw --help
OpenClaw stores its memory, skills and configuration in the openclaw_data named volume. Backing up this volume regularly means you can restore a working installation without repeating onboarding.
Run the following to create a compressed archive in /opt/openclaw/backups:
docker run --rm \
-v openclaw_data:/data \
-v /opt/openclaw/backups:/backup \
alpine tar czf /backup/openclaw-$(date +%Y%m%d).tar.gz -C /data .
To run this automatically each night, add a cron job. Open the crontab editor with crontab -e and add the following line, which runs the backup at 03:00 daily:
0 3 * * * docker run --rm -v openclaw_data:/data -v /opt/openclaw/backups:/backup alpine tar czf /backup/openclaw-$(date +\%Y\%m\%d).tar.gz -C /data . 2>/dev/null
OpenClaw releases new features and integrations frequently. Upgrading pulls the latest image or source code while leaving your data volume untouched.
For official image installs, run the following from /opt/openclaw:
docker compose pull
docker compose up -d
For source builds, pull the latest code first, then rebuild:
cd /opt/openclaw/src
git pull
cd /opt/openclaw
docker compose up -d --build
If the container stops seconds after docker compose up -d, a missing or malformed environment variable is the most common cause. Check the logs for the specific error:
docker compose logs openclaw
.env file is in /opt/openclaw and contains valid credentials.docker-compose.yml is correct and the tag exists on the registry.Exit code 137 means the process was killed by the operating system, almost always because the VPS ran out of memory during the build. The npm install and build steps are memory-intensive.
If docker compose exec openclaw openclaw onboard returns a “command not found” error, the container may not have started correctly or the binary path differs in your build.
docker compose ps.docker compose exec openclaw sh and check what is available in /usr/local/bin or dist/.You have installed OpenClaw on a VPS using Docker Compose, completed first-run onboarding and set up automated daily backups. Your configuration and data persist in a named volume, so upgrades and restarts do not affect your setup.
Now that OpenClaw is running, consider reviewing your VPS firewall rules to confirm the container is not exposing unnecessary ports. Our guides on opening ports in UFW and securing your VPS cover the key steps. For Node.js version management inside your containers, see our guide on managing Node.js versions with NVM.
Our VPS hosting plans give you the root access, RAM and persistent storage that a production OpenClaw deployment needs.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting