DEV Community

Ryo Kuroyanagi
Ryo Kuroyanagi

Posted on

Running WebpackDevServer in Docker

TL;DR A sample project to webpack-dev-server in a Docker container is in this repository.


Sometimes we want to run webpack-dev-server in a Docker container.
The reason might be like following

  • Want to use a specific Node.js version docker image
  • Want to start project in a series of docker-compose services

Key points

There's some key points to run webpack-dev-server in a Docker container.

Needs to run the dev server for

By default, the dev server runs for to enable accessing by localshot:XXXX on browsers. But this does not expose the content outside of a Docker container. You need to listen Ref: What is the difference between, and localhost?

  devServer: {
    compress: false,
    host: "",
    port: 3000,
Enter fullscreen mode Exit fullscreen mode

Naive watch option does not work

By default, the dev server's watch option is enabled and it automatically re-compiles and reloads every time a file changed. However, it does NOT work in the case of running in a Docker container. We need to use the poll option of webpack's watch option.

  watchOptions: {
    poll: 1000,
Enter fullscreen mode Exit fullscreen mode

That's it! Hope this helps :)

Discussion (2)

tqbit profile image

watchOptions saved my nerves. Thank you!

ku6ryo profile image
Ryo Kuroyanagi Author

Grad to hear that ;)