Improve Dockerfile security, layering, and dev/prod parity#6882
Open
Improve Dockerfile security, layering, and dev/prod parity#6882
Conversation
- Run app as non-root user (addgroup/adduser + USER app) - Remove vim from production image - Fix ARG ROOT: remove no-op global declaration, add default per-stage - Copy package*.json before COPY . . to improve npm layer caching - Replace fragile npm symlink with direct COPY from node-source - Add apk cache cleanup to build stage - Align devcontainer Ruby version with production (3.3 → 4.0) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
COPY resolves the file to /usr/local/bin/npm, so Node sets __dirname
to /usr/local/bin/ and require('../lib/cli.js') in npm-cli.js points
to /usr/local/lib/cli.js (missing). A symlink keeps the real file at
/usr/local/lib/node_modules/npm/bin/npm-cli.js so __dirname resolves
correctly and the relative require works.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
appuser instead of rootvimfrom production image (attack surface reduction)ARG ROOT: remove the no-op global declaration; each stage now carries its own default valuepackage*.jsonis copied andnpm ciruns beforeCOPY . ., so source changes don't bust the npm install layerln -sinto node_modules internals withCOPY --from=node-source /usr/local/bin/npmbuildstage (was missing, present in final stage)ruby:dev-3.3-bookworm→ruby:dev-4.0-bookwormto match productionTest plan
docker build .completes without errorsdocker runstarts Rails server and responds on port 3000whoamiinside container returnsapp(notroot)🤖 Generated with Claude Code