我在尝试在React应用程序中构建Docker容器时遇到了权限错误。
我试图利用社区的答案,但没有帮助。
在相关的讨论中,我尝试了:
- 获取当前用户:第一个月
- 标签:
sudo chown -R myUser:myUser /usr/local/lib/node_modules
- 这也抛出了相同的错误:
sudo chown -R ownerName: /usr/local/lib/node_modules
个 - 同样的:
sudo chown -R $USER /usr/local/lib/node_modules
个 - 添加用户没有帮助:
sudo chown -R $USER /app/node_modules
个 - 尝试给予安装此内容的权限:
sudo npm install -g --unsafe-perm=true --allow-root
个 - 另一个尝试是删除node_modules并指定
sudo
安装:sudo npm install
个
将此添加到docker-compose
文件,也没有帮助:
environment:
- CHOKIDAR_USEPOLLING=true
字符串
我正在尝试使用此命令构建:docker-compose up --build
Dockerfile.dev文件
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
型
docker-composite.yml文件
version: "3"
services:
web:
stdin_open: true
environment:
- CHOKIDAR_USEPOLLING=true
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "4000:4000"
volumes:
- /app/node_modules
- .:/app
型
误差,误差
Building web
Step 1/6 : FROM node:alpine
---> 50389f7769d0
Step 2/6 : WORKDIR '/app'
---> Using cache
---> bb4d4ffdeb02
Step 3/6 : COPY package.json .
---> Using cache
---> c4e5fce6b1e0
Step 4/6 : RUN npm install
---> Using cache
---> 9383aea4aba6
Step 5/6 : COPY . .
---> Using cache
---> 98ea3037694f
Step 6/6 : CMD ["npm", "run", "start"]
---> Using cache
---> 6edf3365a6db
Successfully built 6edf3365a6db
Successfully tagged app_web:latest
Starting app_web_1 ...
Starting app_web_1 ... done
Attaching to app_web_1
web_1 |
web_1 | > app@0.1.0 start
web_1 | > react-scripts start
web_1 |
web_1 | ℹ 「wds」: Project is running at http://172.20.0.2/
web_1 | ℹ 「wds」: webpack output is served from
web_1 | ℹ 「wds」: Content not from webpack is served from /app/public
web_1 | ℹ 「wds」: 404s will fallback to /
web_1 | Starting the development server...
web_1 |
web_1 | Failed to compile.
web_1 |
web_1 | EACCES: permission denied, mkdir '/app/node_modules/.cache'
型
任何帮助将不胜感激
2条答案
按热度按时间kcugc4gi1#
试试这个Docker - EACCES: permission denied, mkdir '/app/node_modules/.cache'
这对我很有效
字符串
或sh到docker容器中并运行
型
cqoc49vn2#
你需要把它添加到你的Dockerfile
字符串
COPY . .
和CMD ["npm", "run", "start"
之间]