20

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?

avishorp
  • 3,671
  • 3
  • 18
  • 19
  • can you show us your Dockerfile and your `docker run` command? – hc2p Nov 02 '15 at 09:45
  • I don't have a Dockerfile, I'm running manually from the node:4.2.1 image: `docker -ti -p 8080:8080 node:4.2.1 bash` – avishorp Nov 02 '15 at 15:43
  • 1
    what IP are you trying to connect to? Docker by default binds your port to all the available interfaces which is represented by 0.0.0.0 (INADDR_ANY). If you want it to bind to localhost do `docker -ti -p 127.0.0.1:8080 node:4.2.1 bash` – hc2p Nov 03 '15 at 10:58

2 Answers2

29

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

Thibault Deheurles
  • 1,211
  • 13
  • 21
  • 2
    Webpack is a webserver here. It's default is to be bind to localhost (127.0.0.1). So when you attempt to connect from the host machine to the container, webpack refuse the connection as it's not local. Binding to all ips do the trick. – Thibault Deheurles Oct 06 '16 at 23:15
  • OMG Thanks! this is a life saver. I've spent a day and a half trying to get my MacOS browser to connect to a webpack-dev-server application running on an ubuntu docker container. (Plutus Pioneer Program) – marcel_g Jul 06 '21 at 02:17
2

You need to make sure:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That's exactly what I'm doing. I'm trying to access the container from the computer on which Docker is running, no VM in between them. – avishorp Nov 01 '15 at 14:09
  • @user1442554 so your host is a Linux machine then, not Mac or Windows? – VonC Nov 01 '15 at 14:11
  • @user1442554 and the port is mapped, I presume? – VonC Nov 01 '15 at 21:01
  • What do you mean mapped? The port is open inside the container (I can access it), exposed and published. When I try to access it from outside the container it resets. If the application is not running the connection is refused. – avishorp Nov 01 '15 at 21:17
  • @avishorp I meant published indeed (`-p x:y`) – VonC Nov 01 '15 at 21:53