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 :)

Top comments (3)

tqbit profile image

watchOptions saved my nerves. Thank you!

ku6ryo profile image
Ryo Kuroyanagi

Grad to hear that ;)

serdarde profile image

Thank you!! I was struggling with nuxtjs2. Adding those lines solved the problem:
watchers: {
webpack: {
poll: true,

An Animated Guide to Node.js Event Loop

Node.js doesnโ€™t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.