My dockerfile contents:
FROM node:16.0.0-alpine3.13
RUN addgroup app && adduser -S -G app app
RUN mkdir /app && chown app:app /app
USER app
WORKDIR /app
COPY . .
RUN npm install
When I try to build the container I get this permission error:
npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /app/package-lock.json
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, open '/app/package-lock.json'
npm ERR! [Error: EACCES: permission denied, open '/app/package-lock.json'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/app/package-lock.json'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/app/.npm/_logs/2021-05-08T12_59_30_045Z-debug.log
I don't understand, why I am getting this error as the parent directory is owned by the app
user, and it also have permissions to read package.lock
and package.json
files.
If I remove the RUN npm install
from Dockerfile and build the container, this is the output of ls -l
-rw-r--r-- 1 root root 660074 May 5 12:33 package-lock.json
-rw-r--r-- 1 root root 813 Mar 5 19:00 package.json
The other user have read permission. And that seems to be the permission
npm install
needs.
Why am I getting permission error here?