Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boot2docker on windows - Can't access exposed port

I've installed boot2docker (full install) on Windows 7 and am trying to run the container port redirection demo:

docker run --rm -i -t -p 80:80 nginx

Which looks like it isn't quite finishing properly, it just stops and looks like this:

enter image description here

When I open another git bash shell and run boot2docker ip I get 192.168.59.103, and when I pop that in chrome I get Error code: ERR_CONNECTION_TIMED_OUT

It works fine for me with plain docker on Ubuntu 14.04. What else do I need to do to make it work with boot2docker on windows?

like image 864
Ben Avatar asked Aug 29 '14 01:08

Ben


2 Answers

Looking more closely, my problem is the same as this question: Docker, can't reach “rails server” development from localhost:3000 using docker flag -p 3000:3000

The answer to that question that worked for me was this one, which simply says to run

boot2docker ssh -L 8080:localhost:80

at the terminal before starting boot2docker

In my case I do this (from a git bash terminal):

boot2docker init # from https://github.com/boot2docker/boot2docker
boot2docker up
boot2docker ssh -L 8787:localhost:8787 # sets up port forwarding and starts boot2docker
docker run -d -p 8787:8787 cboettig/rstudio # starts the container I want

then go to my web browser in windows and point it to http://localhost:8787/ and I get a server instance of RStudio. When I'm done:

docker rm -f $(docker ps -a -q) # delete all containers

UPDATE: downgrading to an earlier version of VirtualBox will fix this

After struggling with folder sharing I regressed through previous versions of VirtualBox and found that with version 4.3.12 I could enable folder sharing and have the port forwarded exactly according to the official instructions, that is I could access my docker container at 192.168.59.103. So downgrading VirtualBox is another option for working around this problem.

ANOTHER UPDATE: updating to the new release of v1.3.1 of boot2docker will fix this

This release just came out a week ago and includes VirtualBox Guest Additions, which simplifies all of this. I now simply do

boot2docker ssh # start boot2docker
docker run -d -p 8787:8787 -v /c/Users/foobar:/home/rstudio/foobar rocker/rstudio  

And I get everthing working as expected and can log into RStudio in my browser at http://localhost:8787/ (linux) or http://192.168.59.103:8787 (Windows) and it just works.

In this case I've also got folder sharing working with, /c/Users/foobar corresponding to an existing folder on my computer at C:/Users/foobar, and foobar can be anything. With this method I can read and write files both ways between Windows and RStudio and I don't need to connect to a special IP address like the samba method does in the official docs

like image 81
Ben Avatar answered Nov 13 '22 03:11

Ben


I had this problem too after a couple of failed attempts to boot2docker start. This created multiple entries of host-only networks configured on VirtualBox (VirtualBox Host-Only Ethernet Adapter #2, VirtualBox Host-Only Ethernet Adapter #3), and probably the boot2docker's VM was using a bad one.

I cleaned up using Virtualbox standard UI, leaving only one of the networks and now everything works fine.

I'm using boot2docker 1.5.0.

Just to register something that happened to me, and made me lose a couple of hours.

like image 1
ianribas Avatar answered Nov 13 '22 03:11

ianribas