Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing docker container from iOS Simulator

I am using boot2docker to run Docker images. I know very well that I need to access the boot2docker's IP address in order to access the Docker container.

Basically in terminal it is curl $(boot2docker ip):49155

When I do it this way in Chrome or Safari, everything seems fine. When I enter the address in Safari browser in iOS Simulator (iOS 8), I receive message: Safari cannot open the page because the network connection was lost.

I tried to run some other localhost-ish app - SimpleHTTPServer in Python, accessible via 0.0.0.0:4000 and that seems to work just fine (website loads in the iOS Simulator).

Is this a bug in Docker/iOS Simulator or do I have to do some additional setup?

like image 244
Michal Avatar asked Jan 26 '15 15:01

Michal


1 Answers

boot2docker is a VM running on your machine. Your Mac is the "host" and the boot2docker machine is the "guest". The iOS simulator is also a "guest".

The guest machines can get their network access a number of ways. boot2docker is set up to use NAT, which effectively means that you can get from the guest to anywhere, but you can only get to the guest from your host machine. The iOS simulator is not the host machine (it has its own IP address and its own network interface) so it can't reach the boot2docker guest.

The simplest work-around is to do port forwarding. boot2docker's instructions suggest something like

boot2docker ssh -L 49155:localhost:49155

This causes port 49155 on your host machine (currently doing nothing) to forward all connections to port 49155 on the boot2docker guest.

Now from the iOS simulator, you can reach your server as if it were on the host: 0.0.0.0:49155. If you use a physical iOS device, you'll need to get the external-facing IP address for your Mac and use that.

An alternative to port forwarding like this would be to use Vagrant to set up a VM yourself (running boot2docker or CoreOS or any recent Linux) and have that VM use "bridged" networking (which makes the guest accessible from outside the host).

like image 128
Nathaniel Waisbrot Avatar answered Oct 17 '22 03:10

Nathaniel Waisbrot