Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting webpack-dev-server inside a Docker container from the host

Tags:

docker

webpack

I'm running a webpack-dev-server application inside a Docker container (node:4.2.1). If I try to connect to the server port from within the container - it works fine. However, trying to connect it from the host computer results in reset connection (the port is published, of course). How can I fix it?

like image 297
avishorp Avatar asked Nov 01 '15 12:11

avishorp


People also ask

How do I connect to Docker host?

Use --network="host" in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.

Where does webpack-dev-server serve files from?

Content Base. The webpack-dev-server will serve the files in the current directory, unless you configure a specific content base. Using this config webpack-dev-server will serve the static files in your public folder. It'll watch your source files for changes and when changes are made the bundle will be recompiled.


2 Answers

This issue is not a docker problem.

Add --host=0.0.0.0 to your webpack command.

You need to connect to your page like this:

http://host:port/webpack-dev-server/index.html

Look to the iframe mode

like image 160
Thibault Deheurles Avatar answered Sep 19 '22 12:09

Thibault Deheurles


You need to make sure:

  • you docker container has mapped the EXPOSE'd port to a host port

    docker run -p x:y 
    
  • your VM (if you are using docker machine with a VM) has forwarded that mapped port to the actual host (the host of the VM).
    See "How to access tomcat running in docker container from browser?"

like image 25
VonC Avatar answered Sep 23 '22 12:09

VonC