I’m new to docker and I’m trying to run npm install
as a system user but I can’t do that because this error occured every time and I don’t know what to do.
This is the error massage I got:
38.52 npm ERR! code EACCES
38.52 npm ERR! syscall open
38.52 npm ERR! path /app/package-lock.json
38.52 npm ERR! errno -13
38.52 npm ERR! Error: EACCES: permission denied, open '/app/package-lock.json'
38.52 npm ERR! [Error: EACCES: permission denied, open '/app/package-lock.json'] {
38.52 npm ERR! errno: -13,
38.52 npm ERR! code: 'EACCES',
38.52 npm ERR! syscall: 'open',
38.52 npm ERR! path: '/app/package-lock.json'
38.52 npm ERR! }
38.52 npm ERR!
38.52 npm ERR! The operation was rejected by your operating system.
38.52 npm ERR! It is likely you do not have the permissions to access this file as the current user
38.52 npm ERR!
38.52 npm ERR! If you believe this might be a permissions issue, please double-check the
38.52 npm ERR! permissions of the file and its containing directories, or try running
38.52 npm ERR! the command again as root/Administrator.
38.52
38.52 npm ERR! A complete log of this run can be found in: /home/app/.npm/_logs/2024-04-05T19_43_08_160Z-debug-0.log
------
Dockerfile:8
--------------------
6 | COPY . .
7 |
8 | >>> RUN npm install
9 |
10 | EXPOSE 3000
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: exit code: 243
Here is my docker file:
FROM node:20.12-alpine3.18
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 3000
Is my dockerfile is correct and how i solve this error?
2
Answers
Possibly this problem arises because, as part of your Dockerfile, you switch to a non-root user (app), but the ownership of the files copied into the container might still be under the root user
Try to modify your Dockerfile to include a chown step after copying the files:
To address this issue, adjust your Dockerfile so that the user within the container possesses the required permissions to write to the /app directory and execute npm install without encountering permission conflicts.