Instantly Improve Docker Performance on Mac – Nimbus

Is macOS good for running Docker?

Macs are excellent development platforms. They support Java, Python, Ruby, and many other commonly used development languages. They allow developers to 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 are compatible with the most popular development tools like VS Code, the JetBrains toolbox, and . Docker: which is an important tool for test and production environments.

But Docker’s performance on Mac gets a bad rap. Let’s talk about why that is and what you can do to improve it.

Docker runs differently on macOS than it does on Linux. Docker uses the Linux kernel to manage resources between containers, so Docker applications run on Linux operating systems. But macOS doesn’t have a Linux kernel, so Docker has to run on a Linux virtual machine. This affects performance, and this is exacerbated by certain tools or languages (such as PHP projects that have a high I/O consumption).

Does that make macOS a bad choice for running Docker? Nope.

MacOS is still a good choice for development, and you can do a lot by running containers on a Mac. It’s not the right choice for performance testing, and you’re going to reach 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 apps on a macOS computer is usually a better option than using native installers or even Homebrew. You can start a MySQL database, Nginx web server, or InfluxDB in seconds with Docker, as easily as you can on a Linux development system. That said, in many cases, you may 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 notable differences is with shared file systems. Accessing large files, or large amounts of files, through a virtual machine on macOS will always work worse than native access.

This doesn’t mean that Docker on macOS is always slower than on Linux. For many computing and network operations, performance between macOS and Linux remains comparable, and the performance gains offered by Apple Silicon can help close the performance gap over time.

These performance issues are something Docker is well aware of. This is evidenced by recent versions of Docker Desktop that have experimental features that attempt 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 work better on your Mac, and most of them are by simply changing some settings.

How to get out of trouble (

  • reset changes that worsened performance
  • )

  • Measure and tune system resources
  • Experimental features (new virtualization framework and VirtioFS)
  • Switch to Minikube (instead of a single-node Kubernetes cluster
  • )

  • Remote development (run environments on a remote machine)

Getting out of trouble

Before we begin, let’s discuss what you can do if you change the settings and things go wrong. While not likely, you may be able to adjust a memory or CPU configuration and your containers won’t start. Luckily, Docker’s developers anticipated this and gave you an easy reset of your configuration.

Launch Docker

Desktop and select the error icon at the top right

.

The troubleshooting panel opens

.

Let’s go over these controls from top to bottom:

The first is a

  • quick shortcut to restart Docker on your Mac
  • . The

  • second takes you to a support page with some diagnostics
  • .

  • The third is a shortcut to restarting Kubernetes. We’ll discuss running Kubernetes on a Mac below.
  • The fourth, as it says, will delete cached data and can fix issues with Docker not starting.
  • The fifth button will reset your settings. This is the control that should fix the problems it causes by changing its settings.
  • Finally, you can uninstall Docker from this panel.

So, if you change a configuration and Docker stops working, try the Reset to factory defaults button.

Let’s look at some system configurations that can help with Docker performance.

Measuring and adjusting system

resources

Now, click on the configuration gear

.

Then click Resources in the left menu

.

Here’s where you configure the resources allocated to Docker.

The default values are:

  • Half of available CPUs
  • 2
  • GB memory

  • 1 GB swap

The size and location of the disk image will vary by system. Changing them won’t help with performance.

Depending on the containers you’re running, 2 GB of memory may not be enough. But before you change the configuration, 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 provides you with a list of containers and the resources they are using. The fourth column tells you how much memory a container is using.

Here is the output of Docker

statistics with three

containers running:

With containers for Ubuntu, Nginx, and MariaDB running, my system is using less than 100MB of container memory.

If your system is under more pressure and uses close to the amount of memory allocated on Docker desktop resources, It may start to be swapped and performance will suffer. Adding more memory can help it work better.

Adjusting experimental features

Sometimes adding memory is not enough. Docker has added a couple of experimental features that will hopefully make their way into production at some point in the future. Both deal directly with how Docker runs in a virtual machine on macOS.

Measuring whether these features help with performance and how well depends on how you’re using Docker. You can:

  • Measure the time it takes to boot containers
  • .

  • Measure file system access operations, such as backing up databases, writing large files, or sharing them from a web server

.

You’ll find these features in a menu in the settings panel.

New virtualization framework

The first deals with the virtual machine that Docker uses. Apple introduced a new virtualization framework with Big Sur, but Docker uses hypervisor.framework by default. The new framework may work 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

works much better than the default file sharing mechanism and enabling it can help you with the biggest Docker performance issue on macOS. You must enable the new virtualization framework to use it. Just like virtualization, check the box and click the button to restart Docker to use this.

Minikube

If you’re running a single-node Kubernetes cluster

on your Mac, you have two options: the Kubernetes deployment that Docker includes with Desktop or minikube. Minikube

is not suitable for production environments, and lacks many features compared to a “full” Kubernetes cluster. But it uses considerably less system resources.

Here

is the output of Docker statistics with

a minikube cluster started:

Here’s

Kubernetes:

If you’re developing containers for a Kubernetes system or testing jobs for a system like Argo Workflow or Apache Airflow, minikube will get the job done while using less memory and running fewer containers.

Remote development

Finally, you always have the ability to shift your development environment to a remote cloud or machine. This is a way of working that has been growing in popularity over the years and has become the main form of development in companies like Meta/Facebook, Shopify, Slack, LinkedIn, Palantir and many more. Full disclosure: This is the business Nimbus is in, so if this is something you’re interested in, check us out.

Remote development allows developers to use a virtual machine or container to host their development environment and to write and run their code. Docker (and other tools) run in this remote environment, reducing local development resources, which has the benefit of improving the local computing experience.

It’s pretty easy to set up your own remote development server for individual use and there are online tutorials that show you how to do it. If you’re building this for a team, this becomes increasingly complex, but we’re looking to publish a paper in the near future with guidance on that.

Run 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 run better. We looked at what they were and discussed options to try if it helped. We also discussed how running lightweight tools like minikube (instead of Kubernetes) can also help. And finally, we talk 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 you can’t solve, get in touch with us and we’ll see if we can provide you with more guidance and get you to build and hack quickly.

Liusha is CEO of Nimbus. He is an engineer who has worked at two hyper-growth startups that have come out and then at Facebook/Meta. He found that the cloud development infrastructure at FAANG offers an incredible developer experience, but that even the most successful startups struggle to get it right. He started Nimbus to bring this way of working to everyone else.