I was trying to run a node project container using docker volumes with -
docker run -p 3000:3000 -v /myapp/node_modules -v $(pwd):/myapp batzu/frontend
and got an error -
EACCES: permission denied, mkdir '/myapp/node_modules/.cache'
But when I try to run the same container without the -v flags -
docker run -p 3000:3000 batzu/frontend
The container starts just fine without error.
First docker run logs-
> frontend@0.1.0 start
> react-scripts start
ℹ 「wds」: Project is running at http://172.17.0.2/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /myapp/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
Failed to compile.
EACCES: permission denied, mkdir '/myapp/node_modules/.cache'
Build command used (the app is an example react-app)-
docker build -f Dockerfile.dev -t batzu/frontend .
My Dockerfile.dev -
FROM node:alpine
WORKDIR /myapp
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
package.json
file generated by the react project-
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.7.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2",
"web-vitals": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I tried to sh
into the container and execute npm run start
from it but got the same error even though I am able to execute mkdir '/myapp/node_modules/.cache'
from the shell without any permission error.
I am not able to understand what does the -v /myapp/node_modules
in the docker run exactly does as I was told it is supposed to sort of bookmark the node_modules
folder before we map our working directory to the /myapp/ dir of the container. Why does this cause an error??
Can someone point me the right direction or explain what am I doing wrong or a fix....?
Many thanks in advance :)