Search code examples
gitboot2docker

Accessing server, running on localhost, which is in container?


I have a server running at localhost:3000 in my docker container but I cannot access it from my PC.

I am trying to get this repo working in my docker

https://github.com/tamaspiros/advanced-chat

So i have my docker conatiner/image runnning and then I clone the repo

git clone https://github.com/tamaspiros/advanced-chat

then I do some installs, as instructed in the repo

npm install && bower install

then I start the server, and it starts on IP: 127.0.0.1:3000

npm start

> chat@0.0.1 start /usr/share/nginx/html/web/git/advanced-chat
> node server.js

   info  - socket.io started
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Express server listening on  IP: 127.0.0.1 and port 3000

Then I try and view the server by going to firefox http://192.168.59.103:3000 (127.0.0.1:3000 does not work because of boot2docker) and selecting no proxy in the settings. but I cannot see it I see Unable to connect.

my container port is mapped with -p 3000:3000 my boot2docker ip is '192.168.59.103' $ boot2docker ip 192.168.59.103

I would have thought I could see the server here 192.168.59.103:3000but not sure why I can't? maybe it is my lack of understaning in IP or something else? Can anyone advise?

NOTE I am running windows7 with boot2docker.

EDIT1::

I got that working using your advice and a bit of fiddlling at my end.

But basically I have as follows in my Oracle VM VirtualBox Manager - boot2docker-vm - settings - Network - Port Forwarding Rules:

enter image description here

I had to get the tcp-port3000 to look like this. But I am not fully sure what is going on. Could you kindly help me understand this please?

Note to self: I got this working running meteor in a ubuntu container, which I had some other difficulties.


Solution

  • You need map boot2ip port for windows.

    windows --> port@boot2ip vbox external ip --> port@vm --> port@dock

    if vm is down, VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port3000,tcp,,3000,,3000";

    if vm is running, VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port3000,tcp,,3000,,3000";

    (I'm using Mac, but the theory is same)