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?
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
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With