I just started working with docker today and am blocked on a permissions issue. I don't know what I should be entering to switch the permission. I am assuming it's a chown thing. There are other questions on stack overflow but they did not help me as they were either not Docker specific or did not have a selected answer to the question.
Below is the error
client_1 |
client_1 | > [email protected] start
client_1 | > react-scripts start
client_1 |
client_1 | ℹ 「wds」: Project is running at http://172.19.0.2/
client_1 | ℹ 「wds」: webpack output is served from
client_1 | ℹ 「wds」: Content not from webpack is served from /app/public
client_1 | ℹ 「wds」: 404s will fallback to /
client_1 | Starting the development server...
client_1 |
client_1 | Failed to compile.
client_1 |
client_1 | EACCES: permission denied, mkdir '/app/node_modules/.cache'
My docker-compose.yml looks like this:
version: "3"
services:
client:
stdin_open: true
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
volumes:
- "/app/node_modules"
- "./:/app"
My Dockerfile.dev looks like this:
FROM node:alpine
RUN apk update && apk add git && apk add python make g++
WORKDIR /app
COPY package.json /app
# To Fix Permissions for Packages
RUN npm config set unsafe-perm true
RUN npm install --force
COPY . /app
CMD ["npm", "run", "start"]
I have once had a similar problem. My interpretation was that when the app is run, it is not run as root, so when it tries to create the .cache directory, it does not have the right credentials to do so anymore. I was using a very similar image (node:lts-alpine), and it already came with a node user. What I did, but I am not sure if that is in accordance with the best practices, was creating a file named .cache where it was supposed to be found, changing its ownership so that node could access it and ran the app as node. I actually run the application as node because this I was deploying to heroku, and there the containers are not run as root. In your case, it would look like:
FROM node:alpine
RUN apk update && apk add git && apk add python make g++
WORKDIR /app
COPY package.json /app
# To Fix Permissions for Packages
RUN npm config set unsafe-perm true
RUN npm install --force
COPY . /app
RUN chown -R node /app/node_modules
USER node
CMD ["npm", "run", "start"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With