How to improve Docker performances with WSL 2 on Windows


If you're a developer working on a Windows machine, you may have experienced some frustratingly slow Docker performance. Slow Docker can seriously impact your productivity, especially when dealing with large applications. But don't worry, there's a solution that can help make Docker faster on Windows and speed up your development process. In this blog post, we'll explore how to use Windows Subsystem for Linux (WSL) to optimize Docker's performance on Windows and make your development environment run smoothly.
By the end of this post, you'll have the knowledge you need to boost your Docker performance and streamline your development workflow. So, if you're ready to learn how to make Docker faster on Windows, keep reading!
Prerequisites
In this article, we will assume that you have Docker and WSL installed on your system. If this is not the case, you can refer to the WSL installation guide.
Understand why it is slow
If you develop applications using Docker and WSL, you probably already noticed that since version 2 of WSL, many latencies can be perceived. I personally experienced these latencies with a Symfony project that was located in my Windows file system (and not in WSL, we'll see that it matters). I had to wait for example 10s to 15s to load a page during development.
To be more precise, the project in question was located on my Windows system on the D
drive, which means that, from the point of view of WSL, it was located in the mounted version of the D
drive located in /mnt/d
.
WSL vs WSL 2
Feature | WSL 1 | WSL 2 |
---|---|---|
Integration between Windows and Linux | ✅ | ✅ |
Fast boot times | ✅ | ✅ |
Small resource foot print compared to traditional Virtual Machines | ✅ | ✅ |
Runs with current versions of VMware and VirtualBox | ✅ | ✅ |
Managed VM | ❌ | ✅ |
Full Linux Kernel | ❌ | ✅ |
Full system call compatibility | ❌ | ✅ |
Performance across OS file systems | ✅ | ❌ |
Unfortunately, since WSL version 2, the performance of Windows system file management from WSL has been greatly reduced. Moreover, Symfony, like many other tools, needs to read and write files for instance to update the application cache. That's why the performance was poor.
In addition, as indicated in the formal documentation, although the performance of file management within WSL has been improved, the performance of Windows files has been degraded.
Improving Docker performance
Now that we have seen why the performance was not excellent, let's see how we can correct this problem.
The trick is very simple. Rather than positioning your project on your Windows file architecture, just position it in the file architecture of your WSL distribution. This way, WSL will not be limited by the speed of reading and writing to Windows files.
To facilitate this process, it is recommended to use a tool such as Git to get your project directly from WSL.
Finally, with the new development tools such as VS Code or PHPStorm, development within WSL is particularly easy.
Conclusion
You've made it to the end of this blog post on how to improve Docker performance with WSL on Windows. By now, you should have a good understanding of why Docker can be slow on Windows and how to make it faster by using Windows Subsystem for Linux (WSL).
Whether you're a Symfony developer working on a Windows machine or just interested in improving Docker's performance, implementing these tips can help you optimize your development environment and increase your productivity. With faster Docker performance, you can spend less time waiting for your code to compile and more time focusing on what matters most: building great applications.
So, to recap, using WSL is an effective way to make Docker faster on Windows. By leveraging the power of WSL, you can create a more efficient Symfony development workflow and streamline your processes. If you're ready to get started, go ahead and give these tips a try.