# Query about adding user in dockerfile

**URL:** <https://forum.codewithmosh.com/t/query-about-adding-user-in-dockerfile/4171>\
**Category:** Site Feedback\
**Created:** [April 15, 2021, 9:33pm UTC](https://forum.codewithmosh.com/t/query-about-adding-user-in-dockerfile/4171 "2021-04-15T21:33:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehmusman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/ehmusman/32/1401_2.png) [@ehmusman](https://forum.codewithmosh.com/u/ehmusman)\
**Post date:** [April 15, 2021, 9:33pm UTC](https://forum.codewithmosh.com/t/query-about-adding-user-in-dockerfile/4171/1 "2021-04-15T21:33:25Z")

</div>

Hello there,  
sir, I am stuck on a topic. when I add the user in Dockerfile at the end and building an image from it and after that when I start a container from this image by using the following command  
docker run react-app npm start  
it gives the permission denied error.  
because you an I created build as a root user and defined the new app user at the end. when I following you moved the new user at the top then the permission denied error becomes while building the image. kindly help to resolve this problem. the content of Dockerfile before and after is attaching with this post

Before

FROM node:14.16.1-alpine3.13  
WORKDIR /app/  
COPY package\*.json .  
RUN npm install  
COPY . .  
ENV API\_URL=[https://api.myapp.com](https://api.myapp.com)  
EXPOSE 3000  
RUN addgroup app && adduser -S -G app app  
USER app

creating image from it  
docker build -t react-app

error after running the command “docker run react-app npm start”

"  
ℹ ｢wds｣: Project is running at [http://172.17.0.2/](http://172.17.0.2/)  
ℹ ｢wds｣: webpack output is served from  
ℹ ｢wds｣: Content not from webpack is served from /app/public  
ℹ ｢wds｣: 404s will fallback to /  
Starting the development server…  
Failed to compile.  
EACCES: permission denied, mkdir ‘/app/node\_modules/.cache’

## "

After  
Dockerfile

FROM node:14.16.1-alpine3.13  
RUN addgroup app && adduser -S -G app app  
USER app  
WORKDIR /app/  
COPY package\*.json .  
RUN npm install  
COPY . .  
ENV API\_URL=[https://api.myapp.com](https://api.myapp.com)  
EXPOSE 3000

error while building the image after running command “docker build -t react-app”

"  
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! }

"

---

<div class="post-metadata">

**Author:** ![Salad](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@Salad](https://forum.codewithmosh.com/u/Salad)\
**Post date:** [April 19, 2021, 6:19am UTC](https://forum.codewithmosh.com/t/query-about-adding-user-in-dockerfile/4171/2 "2021-04-19T06:19:27Z")

</div>

## Go with the default user (node). No need to declare explicitly

- I tried custom user “app” but to no success. Same issue will arise in later stages.
