3

I have Grunt running a node connect (grunt-contrib-connect) web server on localhost:8080 in a docker container. I run the container with this command: $ docker run --rm -it -p 8080:8080 js1972/yeoman:v3.

Inside my container I run the grunt connect task with grunt develop.

I'm on a Mac so using boot2docker. boot2docker ip says the host ip is 192.168.59.103 so I should access the connect server with http://192.168.59.103:8080 in my browser.

However this doesn't work and I just get a safari can't connect to server message. (note that the port forwarding works just fine when I use a simple python web server like on the docker website examples.)

Any idea whats wrong here? The same process works perfectly well outside of docker. I've got a feeling its something to do with running Connect on localhost. I've tried various combinations of --add-hosts and -p localhost:8080:8080 and so on to no avail...

If it helps here's my docker file and gruntfile: https://dl.dropboxusercontent.com/u/7546923/Dockerfile https://dl.dropboxusercontent.com/u/7546923/Gruntfile.js

Rgds, Jason.

Jason Scott
  • 643
  • 4
  • 15
  • 2
    try changing "localhost" in connect to "0.0.0.0" – Adrian Mouat Feb 03 '15 at 15:00
  • Thanks Adrian - that did the trick and I would NEVER have thought of it. Need to read up on the difference between 0.0.0.0, localhost and 127.0.0.1 now. ;-) – Jason Scott Feb 04 '15 at 13:39
  • Cool. 0.0.0.0 just listens to all network interfaces. 127.0.0.1 only listens to the local loopback interface IIRC. I'll add an answer if that's ok. – Adrian Mouat Feb 04 '15 at 17:19

2 Answers2

4

Change localhost to 0.0.0.0.

At the moment the container is only listening for internal connections on the local interface. Using 0.0.0.0 will tell it to listen to all interfaces including the one the Docker host is connected to.

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102
2

Modify the ip of the hostname in the connect settings of the Gruntfile:

// The actual grunt server settings
connect: {
  options: {
    port: 8080,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: '0.0.0.0',
    livereload: 35729
  },

And open the server and reload port to the boot2docker vm:

boot2docker poweroff # vm needs to be off to modify the network settings
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntserver,tcp,,8080,,8080"
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntreload,tcp,,35729,,35729"
boot2docker up
Javier Castellanos
  • 9,346
  • 2
  • 15
  • 19