我创建了一个项目的前端和后端,并希望通过一个docker运行一切这里是我的dockerfile
FROM node:20-alpine
RUN mkdir /client && chown -R node:node /client WORKDIR /client USER node
COPY --chown=node:node package*.json ./
RUN npm ci RUN mkdir /client/node_modules/.vite && chown -R node:node /client/node_modules/.vite RUN chmod -R u+rw /client
COPY --chown=node:node . .
字符串
docker-compose.yml
version: "3.4"
services:
client:
image: node:alpine
container_name: client
command: ["-c", "npm run dev"]
entrypoint: /bin/sh
build: ./client
user: "node"
ports:
- 4000:4000
working_dir: /client
volumes:
- ./client:/client
- /client/node_modules/
tty: true
型
启动docker时显示错误
client | VITE v5.0.7 ready in 535 ms
client |
client | ➜ Local: http://localhost:4000/
client | ➜ Network: http://172.18.0.2:4000/
client | ➜ press h + enter to show help
client | Error: EACCES: permission denied, mkdir '/client/node_modules/.vite/deps_temp_9a28dca3'
client | at Object.mkdirSync (node:fs:1380:26)
client | at runOptimizeDeps (file:///client/node_modules/vite/dist/node/chunks/dep-wTaJK0Jt.js:64816:10)
client | at file:///client/node_modules/vite/dist/node/chunks/dep-wTaJK0Jt.js:64199:46
client | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
型
客户端|VITE v5.0.7在535 ms客户端中就绪|客户端|客户端本地:http://localhost:4000/client|网络:http://172.18.0.2:4000/客户端|请按h + enter以显示帮助客户端|错误:EACCES:权限被拒绝,mkdir '/client/node_modules/.vite/deps_temp_9a28dca3'客户端|在Object.mkdirSync(node:fs:1380:26)客户端|在runOptimizeDeps(file:/client/node_modules/vite/dist/node/chunks/dep-wTaJK 0 Jt. js:64816:10)客户端|at file:/client/node_modules/vite/dist/node/chunks/dep-wTaJK0Jt. js:64199:46客户端|在process.processTicksAndRejections(node:internal/process/task_queues:95:5)
适用于windows
我期望工程开始,一切顺利
1条答案
按热度按时间jei2mxaa1#
要解决此问题,您可以修改Dockerfile和Docker Compose配置,以确保为容器中的用户设置正确的权限。
下面是一个更新的Dockerfile,它设置了相应的权限:
字符串
并修改你的docker-compose.yml,以正确的权限挂载卷:
型
所做的更改:
这些调整应该有助于设置正确的权限,并可能解决您在Docker容器中的Vite构建过程中面临的权限拒绝问题。根据您的特定设置需要调整路径和配置。