Docker on Macs without Docker Desktop with Lima and Colima

Docker on Macs without Docker Desktop with Lima and Colima
Photo by Wesson Wang / Unsplash

I used to be under the impression that you just couldn't easily run Docker on an M1 or M2 Mac without Docker Desktop. This is a problem for Enterprise or anyone who really just prefers a CLI solution. The license on Docker Desktop is not permissive for enterprise or business use, and you need to launch Docker Desktop in order to have access to Docker CLI tools, or at least have them do anything. M1 and M2 Macs further compound this issue in a way since virtualization for a Linux and thus Docker environment is not as straightforward.

Enter Lima: a Linux virtual machine CLI tool for MacOS. This tool allows you to easily start Linux virtual machines with a set of basic tools installed, namely containerd or Docker. Colima is another tool around Lima that makes launching those VMs for Docker, Containerd, and Podman use even easier. With Colima, you can start a Docker virtual machine with a single line:

colima start --vm-type=vz --cpu 4 --memory 4 --disk 64 --runtime docker

This will start a virtual machine with 4 CPUs, 4GiB memory, and 64 GiB of disk space and create a Docker socket, meaning that with that command, running docker run hello-world just works. This also requires you to install docker and docker-compose in Brew. But, for someone that started using Docker originally on Linux and then moved to Windows and MacOS, this is a very convenient way to start Docker without Docker Desktop. Best of all, as far as I can tell, it is entirely equivalent to Docker Desktop's own virtual machine, which I believe also relies on QEMU/Apple's virtualization engine under the hood.

The --vm-type=vz flag also enables Rosetta on the virtual machine started by Lima, meaning that you can run both aarch64/ARM64 and Intel/x86_64 architecture images. Intel images run a bit slower than their ARM64 counterparts, but compared to full emulation via QEMU, it works insanely well and fast. This means, for most workloads in Docker, you won't have a significant difference between the two architectures and shouldn't run into Docker platform issues. This feature is limited to MacOS Ventura and up, so old Macs are limited to full emulation (slow) or user mode emulation via QEMU (less slow).

Another side effect of trying Lima also meant that I discovered containerd. I quite like containerd and generally have found it to be a drop-in replacement for Docker. The only problem holding me back from fully using containerd instead of Docker is that most developer tools that integrate with Docker, like VSCode's devcontainer extension, do not also support containerd.