Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create-react-app livereload with Docker on Windows

I'm trying to run docker on Windows 10 (Linux Containers Mode) to run react development workspace. I managed to run React app boilerplate but livereloading is not working.

Here's some details:

  1. Dockerfile is exposing both 5000 and 35729 ports
  2. Files are mounted and created inside the container via docker exec and create-react-app . commands
  3. WS request status is 101 (that's correct)

Dockerfile:

FROM node:latest

#installing react app first
RUN npm install -g create-react-app

VOLUME [ "/application" ]

#First example was EXPOSE 3000 35729
EXPOSE 3000
EXPOSE 35729
  1. Build command: docker build . -t react-image

  2. Run command: docker run -d -p 3000:3000 -p 35729:35729 -v %PATH_TO_APP_FOLDER%\application:/application --name react-container react-image

  3. Exec command: docker exec -it react-container bash

Then inside the container:

  • cd application
  • create-react-app .
  • yarn start

OUTPUT:

Compiled successfully!

You can now view application in the browser.

Local: http://localhost:3000/ On Your Network: http://172.17.0.2:3000/

Note that the development build is not optimized. To create a production build, use yarn build.

Once I open: http://localhost:3000 everything seems to work fine. If I change files from my host machine files are also changed inside the container (checked with cat App.js). But changing files doesn't trigger webpack re-compiling and livereload.

Any suggestions?

Please let me know if I need to provide more details. Thanks

like image 871
Vadym Avatar asked Oct 29 '22 21:10

Vadym


1 Answers

This can be solved by setting watchOptions.poll to true inside the webpack config: References

like image 141
Vadym Avatar answered Nov 09 '22 05:11

Vadym