docker 错误:EACCES:权限被拒绝,mkdir '/client/node_modules/.vite/deps_temp_9a28dca3'

tktrz96b  于 12个月前  发布在  Docker
关注(0)|答案(1)|浏览(165)

我创建了一个项目的前端和后端,并希望通过一个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
我期望工程开始,一切顺利

jei2mxaa

jei2mxaa1#

要解决此问题,您可以修改Dockerfile和Docker Compose配置,以确保为容器中的用户设置正确的权限。
下面是一个更新的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:
    build:
      context: ./client
      dockerfile: Dockerfile
    container_name: client
    command: ["npm", "run", "dev"]
    ports:
      - 4000:4000
    volumes:
      - ./client:/client:delegated
      - /client/node_modules/
    environment:
      - NODE_ENV=development


所做的更改:

  • 使用docker-compose.yml中的context和dockerfile显式指定Dockerfile位置。
  • 使用docker-compose.yml中的delegated选项挂载卷,这允许主机和容器文件系统之间更好的同步和性能。

这些调整应该有助于设置正确的权限,并可能解决您在Docker容器中的Vite构建过程中面临的权限拒绝问题。根据您的特定设置需要调整路径和配置。

相关问题