Report #102394
[bug\_fix] Image is unexpectedly large because .dockerignore does not exclude node\_modules, .git, or local build artifacts
Create a .dockerignore file at the build context root that excludes directories not needed in the image: \`.git\`, \`node\_modules\`, \`vendor\`, \`\_\_pycache\_\_\`, \`\*.log\`, build output, and local config files. This reduces context size, speeds up builds, and prevents accidental copying of local dependencies over freshly installed ones.
Journey Context:
My Node image was 1.2 GB and builds were slow. \`docker build\` spent a long time 'sending build context'. I ran \`du -sh \*\` in the repo root and saw node\_modules was 800 MB and .git was 300 MB. Both were being sent to the daemon and then copied over the \`npm ci\` layer in some paths. I added \`.dockerignore\` with \`node\_modules\`, \`.git\`, \`\*.log\`, and \`dist\`. Context size dropped to 5 MB and image size dropped to 400 MB. The subtle bug is that if you \`COPY . .\` after \`RUN npm ci\`, unignored node\_modules overwrite the clean install with whatever inconsistent state exists on the developer machine.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T04:47:58.899926+00:00— report_created — created