Because Docker runs in a virtual machine on macOS, container operations are slower than they would be on Linux
Instantly Improve Docker Performance on Mac
Is macOS Good for Running Docker?
Macs are excellent development platforms. They support Java, Python, Ruby, and many other commonly used development languages. They let developers open a shell and find an environment that looks a lot like Linux. And many developers appreciate the user experience that Mac and Apple have become famous for. More importantly, Macs support the most popular development tools like VS Code, the JetBrains toolbox, and.. Docker – which is an important tool for testing and production environments.
But Docker's performance on Mac has a poor reputation. Let's talk about why that is and what you can do to improve it.
Docker runs differently on macOS than Linux. Docker uses the Linux kernel to manage resources between containers, so your Docker applications run on the Linux operating systems. But macOS doesn't have a Linux kernel, so Docker has to run in a Linux virtual machine. This affects performance -and this is exacerbated by certain tools or languages (like PHP projects that have heavy I/O consumption).
Does that make macOS a bad choice for running Docker? No.
MacOS is still a good choice for development, and you can get a lot done running containers on a Mac. It's not the right choice for performance testing, and you're going to hit real limits on the size and number of containers you can run depending on CPU and memory—just like you would on any local development machine.
But, running containers instead of native applications on a macOS computer is often a better option than using native installers or even Homebrew. You can fire up a MySQL database, Nginx web server, or InfluxDB in seconds with Docker — just as easily as you can on a Linux development system. That said, in many instances, you might need more CPU and memory than expected or on a Linux machine.
Is Docker on Mac Slow?
Because Docker runs in a virtual machine on macOS, container operations are slower than they would be on Linux. One of the most noticeable differences is with shared filesystems. Accessing large files, or large numbers of files, via a virtual machine in macOS will always perform worse than native access.
This doesn't mean that Docker on macOS is always slower than on Linux. For many compute and network operations, performance between macOS and Linux is still comparable, and performance gains delivered by Apple Silicon may help bridge the performance gap over time.
These performance issues are something that Docker is very aware of. This is evidenced by recent releases of Docker Desktop that have experimental features attempting to address performance on macOS. We'll look at them below as we cover general ways to improve Docker performance.
How Do I Speed Up Docker on My Mac?
There are a few ways you can make Docker run better on your Mac, and most of them are by simply changing a few settings.
- How to get out of trouble (resetting changes that made performance worse)
- Measuring and adjusting system resources
- Experimental features (new virtualization framework and VirtioFS)
- Switching to Minikube (instead of a single-node Kubernetes cluster)
- Remote development (running environments on a remote machine)
How to Get Out of Trouble
Before we start, let's discuss what you can do if you change settings and things go badly. While not likely, it's possible that you could tweak a memory or CPU setting and your containers won't start. Fortunately, Docker's developers anticipated this and gave you an easy to reset your settings.
Start Docker Desktop and select the bug icon on the top right.
This opens the troubleshooting panel.
Let's go over these controls from top to bottom:
- The first is a quick shortcut for restarting Docker on your Mac.
- The second takes you to a support page with some diagnostics.
- The third is a shortcut for restarting Kubernetes. We'll discuss running Kubernetes on a Mac below.
- The fourth, as it says, will delete cached data and may fix issues with Docker not starting.
- The fifth button will reset your settings. This is the control that should fix issues you cause by changing your settings.
- Finally, you can uninstall Docker from this panel.
So, if you change a setting and Docker stops working, try the Reset to factory defaults button.
Let's look at some system settings that can help with Docker performance.
Measuring and Adjusting System Resources
Now, click the settings gear.
Then, click Resources in the menu on the left.
Here's where you configure the resources allocated to Docker.
The defaults are:
- Half of your available CPUs
- 2GB of memory
- 1GB of swap
The disk image size and location will vary based on your system. Changing them won't help with performance.
Depending on the containers you're running, 2GB of memory may not be enough. But before you change the settings, you use the Docker command line to see how much memory your containers are using. (Note that my system is set to 7.90GB because I was using it to run a very large container.)
The docker stats command gives you a listing of containers and the resources they are using. The fourth column tells you how much memory a container is using.
Here's the output from Docker stats with three containers running:
With containers for Ubuntu, Nginx, and MariaDB running, my system is using less than 100MB of memory for containers.
If your system is under more pressure and uses close to the amount of memory allocated in Docker desktop resources, it may start to swap and performance will suffer. Adding more memory may help it run better.
Adjust Experimental Features
Sometimes adding memory isn't enough. Docker has added a pair of experimental features that will, hopefully, make it to production at some point in the future. Both of them deal directly with how Docker runs in a virtual machine on macOS.
Measuring if and how well these features help with performance depends on how you are using Docker. You can:
- Time how long it takes for your containers to start.
- Measure file system access operations, like database backups, writing large files, or sharing them from a web server.
You'll find these features in a menu under the settings panel.
New Virtualization Framework
The first deals with the virtual machine Docker uses. Apple introduced a new virtualization framework with Big Sur, but Docker uses the hypervisor.framework by default. The new framework may perform better, but Docker doesn't provide official support for it yet. To enable the new framework, check the box next to it and click the button to restart Docker. You'll need to restart all your containers, too.
VirtioFS Directory Sharing
VirtioFS performs much better than the default file sharing mechanism and enabling it may help you with Docker's biggest performance problem on macOS. You need to enable the new virtualization framework to use it. Like the virtualization, check the box and click the button to restart Docker to use this.
If you're running a single-node Kubernetes cluster on your Mac, you have two choices: the Kubernetes implementation that Docker includes with Desktop, or minikube.
Minikube isn't suitable for production environments, and it lacks many features when compared to a "full" Kubernetes cluster. But it uses considerably fewer system resources.
Here is the output from Docker stats with a minikube cluster started:
If you're developing containers for a Kubernetes system or testing jobs for a system like Argo Workflow or Apache Airflow, minikube will do the job while using less memory and running fewer containers.
Lastly, you always have the ability to shift your development environment to a cloud or remote machine. This is a way of working that’s been growing in popularity over the years and has become the primary way of developing at companies like Meta/Facebook, Shopify, Slack, LinkedIn, Palantir, and so many more. Full disclosure - this is the business that Nimbus is in, so if this is something you’re interested in check us out.
Remote development lets developers use a VM or container to host their development environment and to write/run their code. Docker (and other tools) are all run in this remote environment — thereby reducing local development resources which has the benefit of improving the local computing experience.
It’s quite easy to set up your own remote development server for individual use and there are tutorials online that show you how. If you’re building this for a team - this becomes increasingly complex but we’re looking to put out an article in the near future with guidance on that.
Running Docker on a Mac
We've looked at a few ways you can improve Docker performance on macOS. Docker Desktop has several built-in settings that you can adjust to help your system perform better. We looked at what they were and discussed options for testing if help. We also discussed how running lighter weight tools like minikube (instead of Kubernetes) can help, too. And, lastly, we talked about how offloading resource consumption to the cloud can be an easy solution.
All this is to say, that while Docker has to run through an extra layer of abstraction on a Mac, it's still perfectly usable for development. If you’re still having issues that you just can’t resolve, get in touch and we’ll see if we can provide some more guidance and get you building and hacking fast.
Liusha is CEO of Nimbus. He's an engineer who's worked at two hyper-growth startups that have exited and then at Facebook/Meta. He found that the cloud dev infra at FAANG delivers an incredible developer experience but that even the most successful startups struggle with getting it right. He started Nimbus to bring this way of working to everyone else.
The Guide to Cloud Dev Environments
Cloud development environments are getting popular. Google uses them. Microsoft Uses them. Facebook uses them. But how and why? And should I use cloud environments? Check out this post to find out.
Instantly Improve Docker Performance on Mac
Running Docker on macOS typically means dealing with a slower, louder, and much hotter Macbook. This is because macOS just doesn't play well with Docker. However, there are easy ways to improve your computing experience - find out how in this post!