#19836: build: multi-stage Dockerfile reduces image size by ~3GB (4.7GB → 1.6GB)
docker
size: S
Cluster:
Bun Runtime and Docker Improvements
## Summary
The current Dockerfile produces a ~4.7GB image (linux/amd64) due to three issues:
1. **`chown -R node:node /app`** duplicates the entire `/app` directory as a new layer (~1.6GB) just to change file ownership
2. **Bun** is installed for build scripts but carried into the final image (~100MB runtime)
3. **Dev dependencies** are not pruned after build
This PR converts to a multi-stage build:
- **Builder stage**: installs bun, runs pnpm install, builds, then prunes dev deps
- **Runtime stage**: uses `node:22-bookworm-slim` (smaller base, digest-pinned) and `COPY --chown=node:node` from builder — sets ownership during copy with zero layer overhead
Also updates `docker-image-digests.test.ts` to validate all `FROM` lines in multi-stage Dockerfiles (not just the first) and allow the `AS <alias>` suffix.
## Results
| | Before | After | Savings |
|---|--------|-------|---------|
| Image size (amd64) | ~4.7 GB | ~1.6 GB | **-3.1 GB (65%)** |
Tested locally — gateway starts and serves WebSocket connections correctly.
## Test plan
- [x] Build image locally with `docker build --platform linux/amd64`
- [x] Verify `node openclaw.mjs --version` returns correct version
- [x] Verify gateway starts with `--allow-unconfigured --bind lan`
- [x] Verify TCP connectivity on port 18789
- [x] Both `FROM` lines pinned to sha256 digests
- [x] Updated digest test passes locally
- [ ] CI pipeline passes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Most Similar PRs
#22491: Use multi-stage docker build to reduce image size from 4.72GB -> 2....
by mm-zacharydavison · 2026-02-21
78.1%
#11818: fix(docker): resolve build hang by using in-place ownership and opt...
by dilly · 2026-02-08
71.9%
#12033: feat(docker): add linux/riscv64 image to Docker release
by gounthar · 2026-02-08
70.0%
#8376: Docker: inline chown to reduce image size and build time
by bugparty · 2026-02-03
68.9%
#12629: Dockerfile: pre-install common CLI tools for agent runtime
by jhs129 · 2026-02-09
67.2%
#11576: Update Dockerfile, change file ownership during copy to prevent long …
by fastali · 2026-02-08
65.8%
#13737: Docker: harden UID/GID remap and docker-setup flow, convenience upd...
by ramarnat · 2026-02-10
65.6%
#8362: Add Homebrew-based Docker image
by bugparty · 2026-02-03
65.6%
#22344: feat(docker): add pre-built image mode for docker-setup
by AIflow-Labs · 2026-02-21
65.0%
#6638: fix: make Dockerfile work on container platforms (Render, Railway, ...
by kaizen403 · 2026-02-01
64.9%