How to get a better disk performance in Docker for Mac

Tom Keur
3 min readDec 21, 2017

--

Follow these small steps to get a better disk performance in Docker for Mac.

Step zero: macOS High Sierra

Before you start, make sure that you’re running macOS High Sierra (10.13) and you’re using APFS as filesystem. Fusion drives are currently not supported. In Disk Utility you can check if you’re using APFS.

Step one: Download and install the Edge version

Note: If you don’t want to install the Edge version, you will have to be patient.

Use the Edge version of Docker Community Edition instead of the stable version. The Edge version can be downloaded from the Docker website.

The Edge version offers cutting edge features and comes with experimental features turned on.

Step two: Disk.raw

Make sure that your disk image is ending in .raw and not it .qcow2
1. Open Docker Preferences -> Disk

2. If you see: Docker.qcow2 or something else than Docker.raw, please reset to factory defaults.
3. Only if you don’t see Docker.raw:
WARNING: Be aware that you’re losing all your Docker containers and images. You’ll need to download all the images again, so a fast internet connection is recommended.

3.1 Reset
3.2 Reset to factory defaults.

Step three: Use cache flags

To improve the file performance, you can add :cached flags to your volumes.
I’m only using them on large mounts (for example Symfony projects in development). Don’t put them on databases, because you want realtime data.

Docker run example:

docker run -v ./html:/var/www/html:cached nginx

Docker compose example:

version: "3.4"
services:
nginx:
image: nginx:alpine
ports:
- 80:80
volumes:
- ./html:/var/www/html:cached

If you don’t want to change your docker-compose.yml file (for example if you’re working on a team with other Linux/Windows users), you can create a
docker-compose.override.yml file:

version: "3.4"
services:
nginx:
volumes:
- ./html:/var/www/html:cached

For more information about the :cached flag, check the Docker website.

Tip: Restart Docker for Mac

I have experienced multiple times that my Docker for Mac was really slow after my Macbook was in hibernation mode. If this is the case: just simple restart Docker for Mac.

Hopefully these tips are giving you a better disk I/O! If you have any tips, please add them :).

--

--