Search code examples
macosnetwork-programmingdockervirtualizationmacos-sierra

How do I debug a network -- probably Hyperkit caused issue -- of a Docker setup on a Mac?


Problem: Network is not routed to the host machine. e.g.:

docker run -tip 80:8080  httpd

does NOT result in apache responding on localhost:8080 on the host machine or on docker.local:8080 or anything like that. If I try to connect from inside, the container works fine:

docker run -ti debian    
curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>

It seems that on the Docker side itself is everything just fine. On docker ps you get: ... 80/tcp, 0.0.0.0:80->8080/tcp ...

Environment: New, clean OS installation - OSX Sierra 10.12.2, Docker.app Version 1.13.0 stable (plus 1.13.0. beta and 1.12.0 beta tried as well with same results).

Assumption: There is something broken in between Docker and OS. I guess that this 'something' is Hyperkit (which is like a black box for me). There might be some settings broken by build script from here: http://bigchaindb-examples.readthedocs.io/en/latest/install.html#the-docker-way which is docker-machine centric, which fact I've probably underestimated. Funny fact is also that this was a new install: this build script was the first thing I've done on it -- I don't know if the networking actually worked before.

Question: How do I diagnose this stuff. I would like to be able to trace where exactly the traffic gets lost and fix it accordingly.


Solution

  • Your command line has the ports reversed:

    docker run -tip 8080:80 httpd
    

    That's the host port first, with an optional interface to bind, followed by the container port. You can also see that in the docker ps output where port 80 on the host is mapped to port 8080 inside the container.

    The other problem some have is the service inside the container needs to listen on all container interfaces (0.0.0.0), not the localhost interface of the container, otherwise the proxy can't forward traffic to it. However, the default settings from official images won't have this issue and your curl command shows that doesn't apply to you.