I'm asking this question because it took me ages to figure out why the networking in my base ubuntu container was so slow, up to 50 times slower than the host OS, which made any kind of apt-get installations take extremely long (45+ minutes in some cases).
How can I make the networking in my container faster?
Simply changing my DNS server instantly fixed the problem. Previously, DNS lookups were taking 5+ seconds, and now they're <.1 second.
Just change the nameserver
lines in /etc/resolv.conf
to:
nameserver 8.8.8.8
nameserver 8.8.4.4
which is Google's DNS Server.
Wanted to post this answer here because I couldn't find this advice anywhere online, and it made a night and day difference for me.
You can also specify the dns server as an argument to docker run
. For example:
docker run --dns 8.8.8.8 <container name>
Chris, do you have any idea why this works or where I can read more about it. Running with your suggested
--dns 8.8.8.8
flag made a huge difference for me as well.I tried, but it seems it doesn't have any effect in my case.
sorry, it does have the effect, but I need to change the DNS in my host first