Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Openclaw Openclaw Docker Image Build

From Leeroopedia


Knowledge Sources
Domains Deployment, Docker
Last Updated 2026-02-06 12:00 GMT

Overview

Docker image build is the concept of containerizing an application by creating Docker images with build-time dependencies separated from runtime to minimize image size and improve security.

Description

When deploying a TypeScript/Node.js application such as OpenClaw, the build process requires a substantial set of tools: pnpm for package management, Bun for script execution, and Node.js for compilation. The resulting runtime, however, only needs Node.js and the compiled output. Containerization encapsulates these concerns into a reproducible, portable artifact.

The OpenClaw Docker build starts from node:22-bookworm, installs Bun and enables corepack, then copies dependency manifests first to leverage Docker layer caching. A full pnpm install --frozen-lockfile ensures deterministic installs. The application source is then copied and built with pnpm build and pnpm ui:build. An optional OPENCLAW_DOCKER_APT_PACKAGES build argument allows injecting extra system packages for specialized deployments.

Security hardening is applied at the image level: the final image switches to the non-root node user (uid 1000) to reduce the attack surface. The default CMD starts the gateway server binding to loopback for security, with documented overrides for container platforms that require external health checks.

Usage

Apply this concept when deploying OpenClaw as a Docker container, whether locally via docker-setup.sh, on a cloud platform such as Fly.io or Render, or in any orchestration system (Kubernetes, Docker Compose). The Dockerfile and docker-setup.sh script together automate building the image and bootstrapping the gateway.

Theoretical Basis

The pattern follows a single-stage build with layer caching optimization:

  1. Dependency layer: Copy only package.json, pnpm-lock.yaml, pnpm-workspace.yaml, .npmrc, workspace sub-package manifests, patches, and scripts. Run pnpm install --frozen-lockfile. This layer is cached as long as dependencies do not change.
  2. Build layer: Copy all source code, run pnpm build and pnpm ui:build. This layer changes when source code changes but does not re-download dependencies.
  3. Runtime configuration: Set NODE_ENV=production, chown files to the node user, switch to non-root, and define the default CMD.

The docker-setup.sh script orchestrates the full flow: it validates prerequisites (Docker, Docker Compose), generates a gateway token, writes environment variables to a .env file, builds the image, runs interactive onboarding, and starts the gateway service via Docker Compose.

The approach prioritizes reproducibility (frozen lockfile), security (non-root user, loopback bind), and operational flexibility (build-arg for extra packages, environment variable overrides for ports, bind mode, and authentication).

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment