【问题标题】:Docker-compose on ViteVite 上的 Docker-compose
【发布时间】:2021-03-14 08:53:06
【问题描述】:

我正在使用 Vue 对接一个 Vite 应用程序。当我从系统运行 yarn dev 时,一切正常,但是当我从 dockerfile 启动相同的命令时,出现以下错误

yarn run v1.22.5

warning package.json: No license field

$ vite

failed to load config from /app/vite.config.ts

error when starting dev server:

Error: spawn Unknown system error -8

我的 dockerfile 是

FROM node:14.16.0-alpine3.13

WORKDIR /app

COPY . .

CMD ["yarn", "dev"]

我的 docker-compose.yml 是

version: '3.8'

services:
  client:
    build: 
      context: ./dockerfiles
      dockerfile: client.dockerfile
    volumes:
      - ./client:/app
    ports:
      - '3000:3000'

我的文件夹结构是

client
|-public
|-src
|-node_modules
|-package.json
|-vite.config.ts
|- ... rest of files
dockerfiles
|-client.dockerfile
docker-compose.yml (at root level)

【问题讨论】:

    标签: node.js docker docker-compose vite


    【解决方案1】:

    我遇到了同样的问题,出于某种原因,docker 使用了项目中的 node_modules 文件夹而不是它自己的文件夹(使用 RUN npm install 命令)。 我通过添加.dockerignore 文件并忽略项目的node_modules 解决了这个问题。

    //.dockerignore
    
    node_modules/*
    

    【讨论】:

    • 救了我。谢谢
    【解决方案2】:

    我还没有完全弄清楚这一点,但我认为它与 alpine 节点图像有关。尝试使用 node 的“纤细”图像之一。

    【讨论】:

      猜你喜欢
      • 2022-10-20
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 2016-03-10
      • 1970-01-01
      • 2017-12-18
      • 2021-02-17
      相关资源
      最近更新 更多