【问题标题】:React App doesn't refresh on changes using Docker-ComposeReact App 不会刷新使用 Docker-Compose 的更改
【发布时间】:2021-05-16 01:30:59
【问题描述】:

考虑 Docker 组合

version: '3'
services:
  frontend:
    build:
      context: ./frontend
    container_name: frontend
    command: npm start
    stdin_open: true
    tty: true
    volumes:
      - ./frontend:/usr/app
    ports:
      - "3000:3000"

  backend:
    build:
      context: ./backend
    container_name: backend
    command: npm start
    environment:
      - PORT=3001
      - MONGO_URL=mongodb://api_mongo:27017
    volumes:
      - ./backend/src:/usr/app/src
    ports:
      - "3001:3001"

  api_mongo:
    image: mongo:latest
    container_name: api_mongo
    volumes:
      - mongodb_api:/data/db
    ports:
      - "27017:27017"
      
volumes: 
    mongodb_api:

还有 React Dockerfile:

FROM node:14.10.1-alpine3.12

WORKDIR /usr/app

COPY package.json .

RUN npm i

COPY . .

文件夹结构: -前端 -后端 -docker-compose.yml

在前端内部:

在 src 里面:

当我更改 src 中的文件时,它不会反映在 Docker 端。

我们如何解决这个问题?

【问题讨论】:

  • 你是说当你重建你的 docker 镜像时,改变没有显示?当您进行更改时,Docker 不会自动重建。
  • @RobBailey:不是在重新构建时,而是在运行 docker-compose 时重新构建它。
  • 你在运行docker-compose up --build --no-cache吗?
  • @RobBailey:docker-compose up --build --no-cache 不起作用,我正在运行docker-compose up --build
  • 我认为这可能是因为您将应用程序的副本存储在卷中。尝试删除卷:- ./frontend:/usr/app

标签: reactjs docker docker-compose


【解决方案1】:

这是答案:

If you are running on Windows, please read this: Create-React-App has some issues detecting when files get changed on Windows based machines. To fix this, please do the following:

1)In the root project directory, create a file called .env

2)Add the following text to the file and save it: CHOKIDAR_USEPOLLING=true

3)That's all!

取自这里: https://github.com/StephenGrider/docker-react/issues/3#issuecomment-508946730

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    相关资源
    最近更新 更多