#8376: Docker: inline chown to reduce image size and build time
docker
stale
Cluster:
Docker Enhancements and Fixes
Move chown operations into the same RUN layer where files are created, avoiding Docker's copy-on-write duplication of entire /app directory.
- Reduces final image size by ~2 GB
- Reduces build time by ~2 minutes
- Applies --chown flag during COPY where possible
- Inline chown in pnpm install and build steps
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the `Dockerfile` to reduce image size/build time by preventing a later full-tree `chown -R /app`. It does this by applying `COPY --chown=node:node` where possible and inlining targeted `chown -R` calls into the same `RUN` steps as `pnpm install`, `pnpm build`, and `pnpm ui:build`, then running the container as the non-root `node` user.
These changes fit the existing Docker build flow (install deps → build server → build UI → run `node dist/index.js ...`) while shifting ownership work earlier and narrowing it to specific directories.
<h3>Confidence Score: 3/5</h3>
- Mostly safe, but Docker build can become more brittle due to unconditional recursive chowns of possibly-missing output directories.
- The changes are localized to the Dockerfile and align with the goal of avoiding a late `chown -R /app`, but the new `chown -R` steps can fail depending on build configuration/output (and recursive chowns can be costly).
- Dockerfile
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#11576: Update Dockerfile, change file ownership during copy to prevent long …
by fastali · 2026-02-08
92.5%
#11818: fix(docker): resolve build hang by using in-place ownership and opt...
by dilly · 2026-02-08
85.8%
#5458: fix: set correct file ownership in Dockerfile (#5450)
by hakyonglee · 2026-01-31
84.1%
#22491: Use multi-stage docker build to reduce image size from 4.72GB -> 2....
by mm-zacharydavison · 2026-02-21
79.5%
#11333: fix(docker): align host directory ownership with container user
by liuxiaopai-ai · 2026-02-07
79.3%
#9102: Remove UI build for Discord-onlyUpdate Dockerfile
by nbliss16 · 2026-02-04
78.7%
#2609: bugfix: Docker build fails on main: .dockerignore excludes required...
by yanquankun · 2026-01-27
78.6%
#4238: Fix/docker migration atomicity
by ricardotrevisan · 2026-01-29
77.7%
#6631: fix: configure npm global prefix for non-root user in Docker
by tjetzinger · 2026-02-01
76.2%
#3240: Fix Docker build failures on Windows/WSL environments
by Attili-sys · 2026-01-28
75.9%