@@ -7,6 +7,7 @@ ENV PATH="/root/.bun/bin:${PATH}"
77RUN corepack enable
88
99WORKDIR /app
10+ RUN chown node:node /app
1011
1112ARG OPENCLAW_DOCKER_APT_PACKAGES=""
1213RUN if [ -n "$OPENCLAW_DOCKER_APT_PACKAGES" ]; then \
@@ -16,23 +17,47 @@ RUN if [ -n "$OPENCLAW_DOCKER_APT_PACKAGES" ]; then \
1617 rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*; \
1718 fi
1819
19- COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
20- COPY ui/package.json ./ui/package.json
21- COPY patches ./patches
22- COPY scripts ./scripts
20+ COPY --chown=node:node package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
21+ COPY --chown=node:node ui/package.json ./ui/package.json
22+ COPY --chown=node:node patches ./patches
23+ COPY --chown=node:node scripts ./scripts
2324
25+ USER node
2426RUN pnpm install --frozen-lockfile
2527
26- COPY . .
28+ # Optionally install Chromium and Xvfb for browser automation.
29+ # Build with: docker build --build-arg OPENCLAW_INSTALL_BROWSER=1 ...
30+ # Adds ~300MB but eliminates the 60-90s Playwright install on every container start.
31+ # Must run after pnpm install so playwright-core is available in node_modules.
32+ USER root
33+ ARG OPENCLAW_INSTALL_BROWSER=""
34+ RUN if [ -n "$OPENCLAW_INSTALL_BROWSER" ]; then \
35+ apt-get update && \
36+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends xvfb && \
37+ mkdir -p /home/node/.cache/ms-playwright && \
38+ PLAYWRIGHT_BROWSERS_PATH=/home/node/.cache/ms-playwright \
39+ node /app/node_modules/playwright-core/cli.js install --with-deps chromium && \
40+ chown -R node:node /home/node/.cache/ms-playwright && \
41+ apt-get clean && \
42+ rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*; \
43+ fi
44+
45+ USER node
46+ COPY --chown=node:node . .
2747RUN pnpm build
2848# Force pnpm for UI build (Bun may fail on ARM/Synology architectures)
2949ENV OPENCLAW_PREFER_PNPM=1
3050RUN pnpm ui:build
3151
52+ ARG OPENCLAW_VERSION=""
53+ ENV OPENCLAW_VERSION=$OPENCLAW_VERSION
54+ ENV OPENCLAW_SERVICE_VERSION=$OPENCLAW_VERSION
55+
3256ENV NODE_ENV=production
3357
3458# ---- add openclaw command ----
3559# Makes `openclaw ...` == `node /app/dist/index.js ...`
60+ USER root
3661RUN printf '%s\n ' \
3762 '#!/bin/sh' \
3863 'set -e' \
@@ -41,11 +66,15 @@ RUN printf '%s\n' \
4166 && chmod +x /usr/local/bin/openclaw
4267# -----------------------------
4368
44- # Allow non-root user to write temp files during runtime/tests.
45- RUN chown -R node:node /app
46-
4769# Security hardening: Run as non-root user
70+ # The node:22-bookworm image includes a 'node' user (uid 1000)
71+ # This reduces the attack surface by preventing container escape via root privileges
4872USER node
4973
5074# Start gateway server with default config.
75+ # Binds to loopback (127.0.0.1) by default for security.
76+ #
77+ # For container platforms requiring external health checks:
78+ # 1. Set OPENCLAW_GATEWAY_TOKEN or OPENCLAW_GATEWAY_PASSWORD env var
79+ # 2. Override CMD: ["node","openclaw.mjs","gateway","--allow-unconfigured","--bind","lan"]
5180CMD ["openclaw" , "gateway" , "--allow-unconfigured" ]
0 commit comments