【发布时间】:2026-01-21 10:25:01
【问题描述】:
我在尝试在 React 应用程序中构建 docker 容器时遇到权限错误。
我试图利用社区的答案,但没有帮助。
关注相关discussion我试过了:
- 我得到当前用户:
id -un - 试过这个:
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-compose.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'
任何帮助将不胜感激
【问题讨论】:
-
你可以试试 Dockerfile 中的
chmod 777 -R吗?只是为了确定问题是什么..