Can't connect to running containers from the osx host
mattreyuk opened this issue · 4 comments
After I run the helper, I can run docker commands, start and stop containers without issue (which is really great). However, if I try and connect to a container that has a port exposed from the osx host either by browser or curl I get a timeout on the VM 192 address and nothing on localhost for that port. If I ssh into the VM, I can curl the exposed ports and get my expected results.
That is expected. Like you say the port is exposed inside the VM that runs the docker daemon.
You will need to further tell you VM infrastructure (presumably virtual box) to expose the port to the host OS.
docker:port -> vm:port -> host:port
Something like this:
#!/bin/bash
VBoxManage showvminfo boot2docker-vm | grep 'NIC [0-9]+ Rule([0-9]+):.name = [tu][cd]p-[0-9]+' | while read a b c d e f g; do
f="${f%%,}"
echo "Closing $f"
VBoxManage controlvm "boot2docker-vm" natpf$b delete "$f"
done
docker ps | fmt -1 | grep '^0.0.0.0:[0-9]+' |
sed 's|.:([0-9])->([0-9])/([tu][dc]p).|\1 \2 \3|g' | while read port vmport protocol; do
#VBoxManage controlvm "boot2docker-vm" natpf1 delete "${protocol}-$vmport" >/dev/null 2>&1 || true
VBoxManage controlvm "boot2docker-vm" natpf1 "${protocol}-$vmport,$protocol,,$port,,$port";
echo "$protocol $vmport -> $port"
done
On Jan 8, 2016, at 9:15 AM, Matt Reynolds notifications@github.com wrote:
After I run the helper, I can run docker commands, start and stop containers without issue (which is really great) However, if I try and connect to a container that has a port exposed from the osx host either by browser or curl I get a timeout on the VM 192 address and nothing on localhost for that port If I ssh into the VM, I can curl the exposed ports and get my expected results
—
Reply to this email directly or view it on GitHub #2.
Thanks for the quick response. I'm not sure I understand though. If I don't run the vpn script (and I'm not on the vpn) provided I mapped the port when I ran my container, I could just go to http://192.168.99.100:8080 say on my Mac browser (which is the ip of the virtual box) and I would see the container output. If I run the vpn script, I can't now. I don't need to see it at localhost:8080 on the Mac which is what I think you're talking about. Does that make sense?
I see. I think that's where the vpn gets you. If you want access you would need to establish the port mapping to localhost.
Sent from my
On Jan 8, 2016, at 12:18 PM, Matt Reynolds notifications@github.com wrote:
Thanks for the quick response. I'm not sure I understand though. If I don't run the vpn script (and I'm not on the vpn) provided I mapped the port when I ran my container, I could just go to http://192.168.99.100:8080 say on my Mac browser (which is the ip of the virtual box) and I would see the container output. If I run the vpn script, I can't now. I don't need to see it at localhost:8080 on the Mac which is what I think you're talking about. Does that make sense?
—
Reply to this email directly or view it on GitHub.
Ah ok thanks.