Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is network/internet in my Docker container so slow?

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?

like image 288
Christopher Shroba Avatar asked Jan 29 '17 17:01

Christopher Shroba


People also ask

Why is Docker so slow on Windows 10?

Why is Docker so slow? The root of the issue is that Windows 10 is (was) using WSL (Windows Subsystem for Linux), which is a layer between Windows and Linux. Communication between these two (Hard Drive operations) can be quite slow. Contents Solution for Docker performance improvement

How to speed up Docker containers?

A multistage build is another fantastic trick you can use to speed up the Docker containers. This will work on the same principles as chaining the RUN commands. With a multistage build, you can significantly reduce the size of a container image. You have to use the FROM command here.

Why is my Docker installation taking so long?

The usual suspects were, of course, configuration errors that we might have made while packaging our product in Docker. However, we couldn’t find anything, that might have caused any slowness, compared to VM or bare metal installations. Everything looked correct. As a next step, we ran all kinds of tests from a Sysbench package.

Why are my containers running slow on Windows 10?

So something that's playing a role here, is that you're running your containers in hyper-v isolation mode by default. If you're using Windows 10 as opposed to Windows Server, this is expected as hyper-v isolation is required when running containers on Windows 10.


1 Answers

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>
like image 96
Christopher Shroba Avatar answered Nov 09 '22 21:11

Christopher Shroba