【问题标题】:Docker-compose with WSL 2 React app not hot reloading on changes使用 WSL 2 React 应用程序的 Docker-compose 不会在更改时热重新加载
【发布时间】:2022-01-03 01:12:23
【问题描述】:

我的 React 应用程序没有在 Docker for Windows 上使用 docker-compose 和 WSL2 重新加载。

docker-compose.yml

frontend:
    container_name: frontend
    build:
      context: ./github-finder-app
    volumes:
      - '/var/app/node_modules'
      - './github-finder-app:/var/app'
    ports:
      - 3000:3000
    stdin_open: true
    environment:
      - CHOKIDAR_USEPOLLING=true
    command: npm start

Dockerfile

FROM node:14.9

WORKDIR /var/app

COPY . .

RUN npm install --only=prod
 
EXPOSE 3000

到目前为止,我一直在尝试使用 Chokidar、.env 文件和不同的 Dockerfile。

【问题讨论】:

  • 你可以试试这里提到的解决方案stackoverflow.com/questions/61576659/…认为环境变量的提及方式不同。
  • 我有错误:services.frontend.environment.0 must be a string
  • 从所提供的代码 sn-p 中,您将其作为布尔值传递。您可以尝试传递我之前评论中提供的链接中提到的字符串吗?环境:CHOKIDAR_USEPOLLING:“真”

标签: reactjs docker webpack docker-compose dockerfile


【解决方案1】:

您可以使用 WebPack 打包工具,顺便说一下 Hot Module Reload 在大多数情况下不会在生产环境中使用(Compact bundle 将运行)。 “HMR 不适合在生产中使用,这意味着它只能在开发中使用。有关更多信息,请参阅构建生产指南。”

参考:https://webpack.js.org/guides/hot-module-replacement/

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-22
  • 2021-05-18
  • 1970-01-01
  • 2021-05-16
  • 1970-01-01
  • 2022-07-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多