0

I've read this post which asks the same question, but the solutions there don't seem to work. Basically I'm trying to access a port on the host os from inside the docker, and I'm using the --net="host" flag as suggested in the linked post. However, I'm still unable to access the port. The only thing that works for me is to run my host web service on 0.0.0.0 and then access it from 192.168.###.###, but that address changes based on what Wifi I'm on, so I don't want to do that. Here's what I've tried:

Set up a test webserver that I can try to access from inside the container:

bash-3.2$ echo hi > index.html
bash-3.2$ python -m SimpleHTTPServer 1234 >/dev/null 2>&1 &
[1] 57942

Curl it from the host to make sure it's running:

bash-3.2$ curl localhost:1234
hi

Start up a container that has curl installed (this is just ubuntu + curl):

bash-3.2$ docker run --rm -it --net="host" tutum/curl bash

Try curling from inside the container:

root@moby:/# curl localhost:1234
curl: (7) Failed to connect to localhost port 1234: Connection refused

I am on macOS, so I'm thinking it might have something to do with the container's host being boot2docker rather than my mac, but I still don't know how to mitigate this.

Any advice would be much appreciated! :)

Community
  • 1
  • 1
Christopher Shroba
  • 7,006
  • 8
  • 40
  • 68
  • I seem to have misread your question. I don't know how to do what you are trying to do, so I will delete my answer. – Dan Lowe Feb 13 '17 at 16:57
  • Thanks anyway, I really appreciate the time you spent trying to help! :) – Christopher Shroba Feb 13 '17 at 17:09
  • I tried exactly the same thing on Ubuntu 14.04 and it just worked. So you are right that it is very likely a `MAC` issue. I don't have any experience on `MAC`, so that is as far as I can help you. – NZD Feb 14 '17 at 06:37
  • This seems to be a bug in Docker for `MAC`. See https://forums.docker.com/t/should-docker-run-net-host-work/14215/10 and https://github.com/docker/for-mac/issues/68 – NZD Feb 14 '17 at 06:41

0 Answers0