Skip to content

Docker Image Bloat - #692

Merged
conservationtimothy merged 1 commit into
mainfrom
fix/673-docker-image-bloat
Sep 21, 2026
Merged

conservationtimothy merged 1 commit into
mainfrom
fix/673-docker-image-bloat

Conversation

@conservationtimothy

@conservationtimothy conservationtimothy commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Goal

Reduce the size of the production Docker image. The image grew from about 600 MB to about 1 GB after the pnpm 11 upgrade. Closes #673 .

Screenshots

CleanShot 2026-09-21 at 12 58 52@2x

App starts up !

What I changed and why

The production image was installing pnpm and running pnpm install --prod, but the running application does not use those production dependencies. Nitro builds a standalone Node server into .output, and the container starts it directly with node .output/server/index.mjs.

I removed the unnecessary production-stage pnpm install and now copy only the files required at runtime: the Nitro .output directory, the start script, and the SQL migration files used by the migration plugin.

This also prevents pnpm’s registry metadata cache under /root/.cache/pnpm from being included in the final image, reducing unnecessary image size. The build stage is unchanged.

How I convinced myself this is right

I compared published images 20260831-1059 (before pnpm 11), 20260902-1066 (pnpm 11), and 20260918-1166 (latest). docker history showed the pnpm install --prod layer growing from 358 MB to 756 MB, while the application output remained about 14 MB. The pnpm 11 image also contained a new ~385 MB cache under /root/.cache/pnpm, along with unused /app/node_modules and the global pnpm installation.

I then built the changed Dockerfile locally. The resulting image was 261 MB uncompressed and 83 MB compressed. The container still exited when database environment variables were missing. With test database environment variables set, the server reached `Listening on http://[::]:8080.

This confirmed that the application can load and start from .output without /app/node_modules.

What I'm not doing here

I do not change the build stage. I do not change the start script or the migration file path.

LLM use disclosure

None

@conservationtimothy
conservationtimothy marked this pull request as draft September 21, 2026 11:54
@conservationtimothy
conservationtimothy marked this pull request as ready for review September 21, 2026 12:00
@IamJeffG
IamJeffG requested review from Atmosfearful and removed request for IamJeffG September 21, 2026 14:12

@Atmosfearful Atmosfearful left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup, agree we don't need pnpm for prod images

@conservationtimothy
conservationtimothy merged commit 4ad2f69 into main Sep 21, 2026
4 checks passed
@conservationtimothy
conservationtimothy deleted the fix/673-docker-image-bloat branch September 21, 2026 15:02
@IamJeffG

Copy link
Copy Markdown
Contributor

what's the new image size?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker image bloat

3 participants