Home > Mobile >  How to fix Dockerfile permission denied to /app?
How to fix Dockerfile permission denied to /app?

Time:11-13

I have a node js project and this is the related Dockerfile:

FROM node:14.16.0-alpine3.13

RUN addgroup app && adduser -S -G app app
RUN mkdir /app && chown app:app /app
USER app

WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

EXPOSE 80

CMD ["npm", "start"]

As you see, I gave the relevant access to the app, but when I run docker-compose up on my ubuntu 18 server, I get this error:

Step 6/9 : RUN npm install
 ---> Running in d95487caef6b
npm WARN checkPermissions Missing write access to /app
npm WARN unihi-backend@1.0.0 No description
npm WARN unihi-backend@1.0.0 No repository field.

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/app'
npm ERR!  [Error: EACCES: permission denied, access '/app'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/app'
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-11-10T10_53_06_750Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 243
ERROR: Service 'api' failed to build : Build failed

Note: api is my app service name.

Also, this project with the same dockerfile is working on my local system (windows).

CodePudding user response:

According to my trial and errors, I realized that instead of this commands:

$ docker-compose build
$ docker-compose up -d

I should use docker-compose up -d --build And then it works correctly.

  • Related