Cannot run webpack-dev-server inside docker

前端 未结 3 1596
遥遥无期
遥遥无期 2021-02-01 20:46

I have created a docker image which serves a simple react app using webpack from inside the container, but I get nothing in the browser.

Here are my config files

相关标签:
3条回答
  • 2021-02-01 21:21

    I just want to add something to Raphayol answer if you couldn't enable hot-reloading of webpack-dev-server inside container.
    I couldn't make webpack or webpack-dev-server watch (--watch) mode work even after mounting my project folder into container.
    To fix this you need to understand how webpack detects file changes within a directory.
    It uses one of 2 softwares that add OS level support for watching for file changes called inotify and fsevent. Standard Docker images usually don't have these (specially inotify for linux) preinstalled so you have to install it in your Dockerfile.
    Look for inotify-tools package in your distro's package manager and install it. fortunately all alpine, debian, centos have this.

    0 讨论(0)
  • 2021-02-01 21:21

    When using webpack-dev-server with Encore and exposing it through Docker, you we'll need to use --host 0.0.0.0 and --public localhost:8080 so files are served even on browsers not navigating to 0.0.0.0 adresses.

    Here is what I used :

    webpack-dev-server --hot --host=0.0.0.0 --public=localhost:8080
    
    0 讨论(0)
  • 2021-02-01 21:34

    You are actualy listening on localhost only. To be reachable from outside replace the following line in your package.json file:

    "start": "webpack-dev-server --inline --content-base ."
    

    by :

    "start": "webpack-dev-server --host 0.0.0.0 --inline --content-base ."
    

    Related discussion : https://github.com/webpack/webpack-dev-server/issues/147

    0 讨论(0)
提交回复
热议问题