Fix: Pre-create node_modules with correct ownership for non-root users#2485
Open
mulder999 wants to merge 1 commit intonodejs:mainfrom
Open
Fix: Pre-create node_modules with correct ownership for non-root users#2485mulder999 wants to merge 1 commit intonodejs:mainfrom
mulder999 wants to merge 1 commit intonodejs:mainfrom
Conversation
Ensure the node_modules folder exists and is owned by the 'node' user to prevent permission issues (EACCES) when mounting volumes.
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.
Description
This PR ensures that the node_modules directory is explicitly created and owned by the node user during the image build process.
Currently, if a volume is mounted to
/home/node/node_modulesand the directory does not exist in the image, Docker creates it withroot:rootownership. This prevents the non-root node user from performing npm install or updating dependencies at runtime, leading to EACCES errors.Changes
Updated the user creation layer to:
/home/node/node_modulesdirectory withnode:nodepermissions.Why this is necessary
When running in environments like Docker Swarm or Kubernetes, persistent volumes or bind mounts are often used to cache node_modules. If the container process runs as a non-root user (UID 1000), it lacks the privileges to modify directories created by the Docker daemon (UID 0). By defining this directory in the Dockerfile, we establish the correct metadata before any volume masking occurs.
Testing Details
Original behavior (problem)
touch: cannot touch '/home/node/node_modules/.test_file': Permission deniedImproved behavior (this PR)
Types of changes
Checklist