FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package*.json ./
RUN npm install
COPY . .
ENV APP_URL=http://api.myapp.com
EXPOSE 3000
CMD ["npm", "start"]
This is my docker file. I am trying to dockerize a sample react-app. I added user in group and then using that user for further commands as you can see this in second line of this code. I believe by default, only root user has access to write to these files and in order to do changes in these files, root user should not be user. Hence I created app user here.
But after running docker build -t react-app.. I am getting the following error -
What am I doing wrong here? Any suggestions?


RUN ls -laandRUN whoamiafterCOPY package*.json ./and let us know what the output is?USER apponly at the very very end where you specify the runtimeCMDas well. This will let the installation run, but prevent the application from modifying its own source or assets.COPY package.json ./?package-lock.jsonmight cause problem.npm start,permissions deniederror is again thrown for which I came upon on this solution that we should not use root user. Plus it is not recommended as well.