The most performant Docker setup on macOS (Apple Silicon M1, M2, M3) for x64 / amd64 compatibility. Bonus: multiple machines simultaneously!

Guillem Riera
3 min readMar 8, 2024
Photo by Markus Spiske on Unsplash

In the past years I have been using mostly Podman as a Docker replacement for most of my workflows. I wrote about it in several posts:

Recently I was working in a project with heavy workloads, all of which run in amd64 containers (including legacy ElasticSearch versions and MySQL versions).

Performance was becoming increasingly an issue, so I started looking at alternatives for my use case.

I came across colima in the past, but it wasn’t until now that I started using it daily.

With the possibility to use Apple’s hypervisor and the rosetta translation layer, it currently tops Podman on performance.

How does it work?

We install colima, and the docker CLI. We then launch a VM using special configuration flags to use macOS’s virtualisation layer and the translation of x86/amd64 into Apple Silicon.

Colima is only a wrapper to create Lima VMs.

Lima is the virtual machine that will run with the rosetta enhaced compatibility with x86 / amd64 and provide the docker runtime.

installation

brew install colima # we will create the lima vm with this wrapper
brew install docker # The CLI only

Create and Configure a super performant vm

Note: adjust your settings (CPU, Memory and Disk according to your needs and hardware)

colima start \
--profile default \
--activate \
--arch aarch64 \
--cpu 10 \
--disk 48 \
--memory 24 \
--mount ${HOME}:w \
--mount-inotify \
--ssh-agent \
--vm-type vz \
--vz-rosetta \
--verbose

Key Configuration Settings

  • arch: AARCH64 specifies that we will run an ARM64 machine and not an x86_64 machine
  • vm-type: VZ (to use Apple’s Hypervisor.Framework)
  • vz-rosseta: Enables Rosetta (needs macOS 13.0 or newer)

Reference on how to use Rosetta with Lima and the compatibility modes:

Configure the Shell to replace Docker

Wait for the machine to come up and then let’s setup the docker environment. (Actually, none of this is strictly necessary. You could use the bundled nerdctl tool.)

But follow along if you want a drop-in Docker replacement:

  • Place those in your shell’s profile or in the current session at will.
export COLIMA_VM="default"
export COLIMA_VM_SOCKET="${HOME}/.colima/${COLIMA_VM}/docker.sock"
export DOCKER_HOST="unix://${COLIMA_VM_SOCKET}"

Bonus: Multiple machines simultaneously

At a certain point you might want to run more experiments or even split work / load / whatever.

For example, one limitation of using Apple’s Hypervisor is that it is not possible to resize the VM’s Disk after being created. So instead of destroying the VM and recreating it (losing all the containers), you can sidekick another alongside and split the load on that one.

Podman does not officially support this kind of workloads, though it is still possible to achieve the same.

To create a secondary machine, just do issue another colima command

colima start \
--profile secondary \
--activate \
--arch aarch64 \
--cpu 1 \
--disk 20\
--memory 8 \
--mount ${HOME}:w \
--mount-inotify \
--ssh-agent \
--vm-type vz \
--vz-rosetta \
--verbose
export COLIMA_VM="secondary"
export COLIMA_VM_SOCKET="${HOME}/.colima/${COLIMA_VM}/docker.sock"
export DOCKER_HOST="unix://${COLIMA_VM_SOCKET}"

That’s it.

Enjoy!.

--

--

Guillem Riera

Principal Technical Consultant, DevOps, CICD Architect