Macos – HTTP / HTTPS connections very slow in Docker for Mac

dockermacos

I'm using Docker for Mac v 1.12.3, the problem I am having is that that HTTP and HTTPS connections are very slow. DNS and Ping seem fine but HTTP(S) takes for example 5 seconds on the docker image but 0.05 seconds on the host:

Host (MacOS Sierra):
time curl www.google.com
0.05 real 
0.00 user 
0.00 sys

Docker:
time curl www.google.com
real 0m5.615s
user 0m0.010s
sys 0m0.000s

I can't see any reason for this or any other people with the same issue.

Any ideas?

Best Answer

  • I noticed that /etc/resolv.conf had 10 different nameserver entries (similar to 192.168.65.1). Adding Google's DNS before any of those got rid of all the lag.

    UPDATE: You might find (as I did) that the change via the moby debian host (below), doesn't actually persist across restarts. I found that v1.12.3 of Docker for Mac does now, however, respect both the --dns flag for the run command, as well as the dns property in a compose file. If you use the --dns flag, you don't need to modify any resolv.conf with the flag, it will override all the nameserver entries for you.

    Doing further digging revealed that I needed to login to the moby image to modify the defaults. You can confirm this by looking at the resolv.conf of any of the images you've built. If they don't have a known-DNS, then you need to follow the directions here:

    https://github.com/docker/docker/issues/24344#issuecomment-239942428

  • Related Question