vscode enhancementsDevelopment on Docker with Remote-Containers does not reflect React in real time

Asked 2 years ago, Updated 2 years ago, 139 views

I configured Dockerfile and docker-compose.yml as follows.

Dockerfile:

 FROM node:16

docker-compose:

version:"3"
services:
  node:
    build:.
    ports:
      - "3000:3000"
    volumes:
      - ./ : /tmp/working
    working_dir: /tmp/working

We built the docker image using Remote-Containers from above vscode with these configuration files.
Then, npx create-react-app app, go to /app and run yarn start.
The browser displays the initial react screen, but changing and saving App.js does not reflect it.
How can I configure my changes to take effect in real time?

docker reactjs docker-compose

2022-09-30 16:20

1 Answers

I didn't try it with create-react-app, but is there probably a working directory (host side mounted in volumes) on the Windows file system?

The chokidar used for change detection is not able to detect the change, so you can expect it to work by polling the environment variable CHOKIDAR_USEPOLLING=true.
https://stackoverflow.com/questions/44643045/running-development-server-with-create-react-app-inside-of-a-docker-container

If the environment shown at the beginning, especially if Docker is using WSL2, it is recommended that the host-side workspace be placed in other distributions of WSL2.This allows fs inside and outside the container to work together natively, detect changes, and speed up I/O.


2022-09-30 16:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.