Run OpenClaw 24/7 on GCP with Docker
I spent way too much time restarting my local dev environment every time my laptop went to sleep or the Wi-Fi flickered. If you want your agents to be useful, they need to stay awake. I found that running OpenClaw on a GCP Compute Engine instance is the best way to get 24/7 uptime for about $5 to $12 a month. It is quiet, cheap, and stays out of the way.
In this guide, I will show you how to set up a persistent Gateway on Google Cloud. We will use Docker to keep things clean and SSH tunnels to keep things secure.
What You’ll Need
Section titled “What You’ll Need”- A Google Cloud account (the free tier works, but I suggest a paid instance for better speed).
- The
gcloudCLI installed on your machine. - Basic knowledge of Docker and the command line.
- Your API keys for models or messaging providers.
Quick Start
Section titled “Quick Start”If you have done this before, here is the 5-minute path to getting live:
- Create the VM: Spin up an
e2-smallinstance running Debian 12. - Install Docker: Run the official install script and add your user to the docker group.
- Clone & Config: Pull the OpenClaw repo and set up your
.envanddocker-compose.yml. - Build & Run: Build the custom image with your binaries and start the container.
1. Prepare your GCP Project
Section titled “1. Prepare your GCP Project”First, you need a place for your VM to live. Open your terminal and run these commands to create a project and enable the right APIs.
# Create the projectgcloud projects create my-openclaw-project --name="OpenClaw Gateway"gcloud config set project my-openclaw-project
# Enable the Compute APIgcloud services enable compute.googleapis.comMake sure you enable billing in the Cloud Console or the VM will not start.
2. Create the VM
Section titled “2. Create the VM”I recommend the e2-small machine type. The e2-micro is often free, but it tends to run out of memory when you start running complex tasks.
gcloud compute instances create openclaw-gateway \ --zone=us-central1-a \ --machine-type=e2-small \ --boot-disk-size=20GB \ --image-family=debian-12 \ --image-project=debian-cloud3. Set Up Docker
Section titled “3. Set Up Docker”SSH into your new VM. Note that it might take a minute for the VM to accept connections after it is first created.
gcloud compute ssh openclaw-gateway --zone=us-central1-aOnce you are in, run this to get Docker ready:
sudo apt-get updatesudo apt-get install -y git curl ca-certificatescurl -fsSL https://get.docker.com | sudo shsudo usermod -aG docker $USERexitLog back in so the group changes take effect.
4. Configure OpenClaw
Section titled “4. Configure OpenClaw”Now we pull the code and set up our environment. I like to keep the configuration files on the host machine so they don’t disappear when the container updates.
git clone https://github.com/openclaw/openclaw.gitcd openclawmkdir -p ~/.openclaw/workspaceCreate a .env file in the openclaw folder. Use openssl rand -hex 32 to create a strong token for your OPENCLAW_GATEWAY_TOKEN.
OPENCLAW_IMAGE=openclaw:latestOPENCLAW_GATEWAY_TOKEN=your-secure-tokenOPENCLAW_GATEWAY_BIND=lanOPENCLAW_GATEWAY_PORT=18789OPENCLAW_CONFIG_DIR=/home/$USER/.openclawOPENCLAW_WORKSPACE_DIR=/home/$USER/.openclaw/workspaceGOG_KEYRING_PASSWORD=your-keyring-passXDG_CONFIG_HOME=/home/node/.openclaw5. Build the Custom Image
Section titled “5. Build the Custom Image”You cannot just install tools like wacli or gog while the container is running because they will vanish on restart. You have to bake them into the image. Update your Dockerfile with the tools you need.
FROM node:22-bookwormRUN apt-get update && apt-get install -y socat && rm -rf /var/lib/apt/lists/*
# Install your required binariesRUN curl -L https://github.com/steipete/gog/releases/latest/download/gog_Linux_x86_64.tar.gz | tar -xz -C /usr/local/binRUN curl -L https://github.com/steipete/wacli/releases/latest/download/wacli_Linux_x86_64.tar.gz | tar -xz -C /usr/local/binRUN curl -L https://github.com/steipete/goplaces/releases/latest/download/goplaces_Linux_x86_64.tar.gz | tar -xz -C /usr/local/binRUN apt-get install -y ffmpeg
WORKDIR /appCOPY . .RUN corepack enable && pnpm install && pnpm build && pnpm ui:install && pnpm ui:buildCMD ["node","dist/index.js"]Launch the gateway:
docker compose builddocker compose up -d6. Access the UI
Section titled “6. Access the UI”The safest way to use the Control UI is through an SSH tunnel. This keeps the port closed to the public internet. Run this on your local laptop:
gcloud compute ssh openclaw-gateway --zone=us-central1-a -- -L 18789:127.0.0.1:18789Now open http://127.0.0.1:18789/ in your browser and enter your token.
Troubleshooting
Section titled “Troubleshooting”Connection Refused If you just created the VM, wait two minutes. Google needs a moment to set up your SSH keys.
Out of Memory (OOM) Errors
If the logs show “Killed” or memory errors, you need a bigger VM. Stop the instance, change the machine type to e2-medium, and start it again.
Binaries are missing
If which gog returns nothing inside the container, you forgot to rebuild. Run docker compose build --no-cache to make sure your Dockerfile changes are applied.
Permission Denied
Make sure your host folders (~/.openclaw) have the right permissions so the Docker user can write to them.
Still stuck? Use the AI Setup Assistant for real-time help.
What’s Next
Section titled “What’s Next”OpenClaw Expert
Still stuck?
If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.