Docker on Mac Performance: Docker Machine vs Docker for Mac

One of the key advantages of Docker is the ability to run Docker Images on any operating system. An image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software. At amazee.io, we use Docker Images to provide our clients the exact same services and configurations from production, for use as a local development environment.

On Linux systems, Docker directly leverages the kernel of the host system, and file system mounts are native.

On Windows and Mac, it’s slightly different. These operating systems do not provide a Linux Kernel, so Docker starts a virtual machine with a small Linux installed and runs Docker containers in there. File system mounts are also not possible natively and need a helper-system in between, which both Docker and Cachalot provide.

The first approach: Docker Machine

Docker Machine was the first approach to run Docker on either Mac or Windows. It is essentially a set of CLI tools that start a boot2docker virtual machine inside a provided hypervisor (like VirtualBox, Parallels, and VMWare). File system mounts are either provided via the hypervisor itself or (as the hypervisor is usually rather slow) an additional tool like NFS.

At amazee.io, we started using Docker when Docker Machine was the only available option. For this reason, we implemented ‘cachalot’, which uses NFS for the File system mounts. It provides decent speeds and with that allows to mount full Drupal directories into the container.

The new kid on the block: Docker for Mac

In June 2016 Docker announced Docker for Mac. The “new” way to run Docker on Mac with much easier installation and a more Linux-y experience for Docker users. Docker for Mac still starts a virtual machine (even though it is super hidden). It also brought its own hypervisor “hyperkit” and shared file system “osxfs”. Unfortunately, “osxfs” wasn’t very fast, and from the beginning there have been long discussions about it (Docker, Github).

Since amazee.io runs mostly Drupal (which had some of the worst performance experiences on Docker for Mac), we decided to implemented support for Docker for Mac, and suggest using cachalot until the performance issues with osxfs are resolved.

Performance Improvements for Docker for Mac

Docker has steadily been working on performance improvements for Docker for Mac and released improvements with 17.04 CE. 17.04 CE now brings new performance flags to mountpoints of Docker Volumes (“delegated” and “cached”). Docker talks about an 2x — 3.5x improvement when comparing Docker for Mac 17.04 CE vs older versions. Currently both flags behave the same, but in the near future they will have different technical implementations (see this GitHub issue to learn more).

Performance Test bench

As amazee.io we are interested in also comparing performance between our current suggested system to Docker for Mac.

For that we have created a small test bench: https://github.com/amazeeio/docker-performance-testbench

This test bench compares Docker Machine Cachalot vs Docker for Mac with the two new mount flags. It does this by installing a new Drupal site (which is a good comparison for an file mount heavy task), as Drupal needs to check which modules are installed and create the symfony php container cache. It also runs a composer install and Drupal Cache clears. More information about how this works can be found in the git repo.

The results

Full results

Our tests show that Docker Machine still has a slight speed advantage compared to Docker for Mac, but Docker for Mac is getting faster, especially compared to the ‘consistent’ flag, which is basically how Docker for Mac was running until now.

Docker itself will continue working on performance improvements like lazy cache invalidation, kernel patches, and more. We are looking forward to these improvements and are super happy that Docker for Mac is getting faster with every release.

As soon as Docker for Mac is faster than Docker Machine, we will also provide a migration path for all our clients.