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.

Implementation:Openclaw Openclaw DockerSetupScript

From Leeroopedia


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

Overview

Concrete tool for building and bootstrapping the OpenClaw Docker deployment provided by the docker-setup.sh script and the Dockerfile.

Description

The docker-setup.sh script is the primary entry point for Docker-based OpenClaw deployments. It validates that Docker and Docker Compose are available, sets up configuration and workspace directories, generates a secure gateway authentication token (via openssl or Python fallback), persists all environment variables to a .env file, and orchestrates the full build-onboard-start lifecycle.

The Dockerfile defines how the OpenClaw image is constructed: it starts from node:22-bookworm, installs Bun, enables corepack, optionally installs extra APT packages, performs a deterministic pnpm install, builds the TypeScript source and UI, hardens with non-root execution, and sets the default gateway command.

The script also supports advanced configuration through environment variables such as OPENCLAW_EXTRA_MOUNTS for additional volume mounts and OPENCLAW_HOME_VOLUME for named Docker volumes, generating a docker-compose.extra.yml overlay when needed.

Usage

Run docker-setup.sh from the repository root to perform a complete Docker deployment. The script handles building, onboarding, and starting the gateway in one flow.

Code Reference

Source Location

  • Repository: openclaw
  • File: docker-setup.sh (lines 173-178 for build step), Dockerfile (lines 1-49)

Signature

# docker-setup.sh - Build step (lines 173-178)
echo "==> Building Docker image: $IMAGE_NAME"
docker build \
  --build-arg "OPENCLAW_DOCKER_APT_PACKAGES=${OPENCLAW_DOCKER_APT_PACKAGES}" \
  -t "$IMAGE_NAME" \
  -f "$ROOT_DIR/Dockerfile" \
  "$ROOT_DIR"
# Dockerfile (lines 1-49)
FROM node:22-bookworm

RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:${PATH}"

RUN corepack enable

WORKDIR /app

ARG OPENCLAW_DOCKER_APT_PACKAGES=""
RUN if [ -n "$OPENCLAW_DOCKER_APT_PACKAGES" ]; then \
      apt-get update && \
      DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $OPENCLAW_DOCKER_APT_PACKAGES && \
      apt-get clean && \
      rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*; \
    fi

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
COPY ui/package.json ./ui/package.json
COPY patches ./patches
COPY scripts ./scripts

RUN pnpm install --frozen-lockfile

COPY . .
RUN OPENCLAW_A2UI_SKIP_MISSING=1 pnpm build
ENV OPENCLAW_PREFER_PNPM=1
RUN pnpm ui:build

ENV NODE_ENV=production

RUN chown -R node:node /app

USER node

CMD ["node", "dist/index.js", "gateway", "--allow-unconfigured"]

Import

# No import needed; run the script directly:
./docker-setup.sh

I/O Contract

Inputs

Name Type Required Description
OPENCLAW_IMAGE string (env var) No Docker image name/tag. Defaults to openclaw:local.
OPENCLAW_CONFIG_DIR string (env var) No Host path for OpenClaw config. Defaults to $HOME/.openclaw.
OPENCLAW_WORKSPACE_DIR string (env var) No Host path for workspace data. Defaults to $HOME/.openclaw/workspace.
OPENCLAW_GATEWAY_PORT string (env var) No Host port for the gateway. Defaults to 18789.
OPENCLAW_BRIDGE_PORT string (env var) No Host port for the bridge. Defaults to 18790.
OPENCLAW_GATEWAY_BIND string (env var) No Gateway bind mode. Defaults to lan.
OPENCLAW_GATEWAY_TOKEN string (env var) No Gateway auth token. Auto-generated if not set.
OPENCLAW_DOCKER_APT_PACKAGES string (env var) No Space-separated list of extra APT packages to install in the image.
OPENCLAW_EXTRA_MOUNTS string (env var) No Comma-separated list of additional Docker volume mounts.
OPENCLAW_HOME_VOLUME string (env var) No Named Docker volume for the home directory.

Outputs

Name Type Description
Docker image Docker image Built image tagged as $OPENCLAW_IMAGE.
.env file File Environment variables persisted for Docker Compose.
Running gateway Docker container The openclaw-gateway service started via Docker Compose.

Usage Examples

Basic Usage

# Default build and start
./docker-setup.sh

# Custom image name and extra packages
OPENCLAW_IMAGE=my-openclaw:v1 \
OPENCLAW_DOCKER_APT_PACKAGES="ffmpeg imagemagick" \
./docker-setup.sh

Post-Setup Commands

# View gateway logs
docker compose -f docker-compose.yml logs -f openclaw-gateway

# Run health check
docker compose -f docker-compose.yml exec openclaw-gateway \
  node dist/index.js health --token "$OPENCLAW_GATEWAY_TOKEN"

# Add a Telegram channel
docker compose -f docker-compose.yml run --rm openclaw-cli \
  channels add --channel telegram --token <token>

Related Pages

Implements Principle

Requires Environment

Page Connections

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