I use Docker containers to automate the setup of development environments in a standard and repeatable way. It makes it very easy to spin up applications locally during development, and especially to ensure everyone working in a team has a consistent environment.
The Docker Engine is actually built on top of a few Linux technologies, including Kernel namespaces and control groups (cgroups), and various filesystem layers. They work together to isolate what’s in the container from your computer, whilst sharing the common pieces, to avoid duplication.
But the Mac does not use the Linux kernel, it uses the Darwin hybrid kernel. So how can we run technology built for Linux on a different Kernel?
Virtualisation
The answer is virtualisation, where we create a virtual version of our computer at the hardware level, but run a different operating system inside it, in this case Linux!
When you install Docker Desktop on a Mac, this is exactly what is happening behind the scenes:
- A Linux virtual machine (VM) is created behind the scenes, and the Docker Engine is installed inside it.
- Docker command line tools are installed onto your Mac, and configured to talk to the Docker Engine inside the Linux VM.
In this way, Docker Desktop provides a turnkey solution for running Docker on a Mac.
Older versions of Docker Desktop used a technology called HyperKit to manage the VM, but have more recently transitioned to Apple’s Virtualization Framework which provides greater performance, thanks to support for the Virtual I/O Device specification.
Colima
Recent licensing changes made it quite a bit more expensive for businesses to use Docker Desktop, but there are free and open source alternatives.
Colima is a free and open source project which handles running Docker Engine inside a lightweight Alpine Linux virtual machine. It is a little more work to get started, but once you’re up and running it acts like a drop-in replacement, compatible with all the same Docker commands you are used to.
.](https://rylon.dev/wp-content/uploads/2023/07/alpine-docker.png?w=900)
Installing
You will need to make sure you have Homebrew installed first. Next, quit Docker Desktop, then run the following commands:
# Install Colima and the Docker command line tools:
brew install colima docker docker-compose docker-buildx
# Enable the Compose and BuildKit plugins:
mkdir -p ~/.docker/cli-plugins
ln -sfn $(brew --prefix)/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
ln -sfn $(brew --prefix)/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx
# Add the following to your zsh/bash profile, so Docker can find Colima:
# (don't forget to reload your shell)
export DOCKER_HOST="unix://${HOME}/.colima/default/docker.sock"
Now you’re ready to create the virtual machine where the Docker Engine will run, using the correct command for your version of macOS:
- macOS 13 “Ventura” – uses macOS Virtualisation Framework with Virtiofs for the best possible performance:
$ colima start --vm-type vz --mount-type virtiofs - macOS 12 “Monterey” or older – uses QEMU with SSHFS
$ colima start
Colima will use 2 vCPUs and 2GB RAM by default, but if you run a lot of containers at once, you may need to adjust that. For example, to double the resources, add --cpu 4 --memory 4 to the colima start command you used above.
You can now verify everything is running properly:
$ colima status
INFO[0000] colima is running using macOS Virtualization.Framework
INFO[0000] arch: aarch64
INFO[0000] runtime: docker
INFO[0000] mountType: virtiofs
INFO[0000] socket: unix:///Users/ryan/.colima/default/docker.sock
$ docker system info | grep Operating
Operating System: Alpine Linux v3.16 # if it says Docker Desktop here then something is wrong
You should now be able to use docker and docker compose commands normally, they should all Just Work™ transparently.
When you next reboot your Mac, you will need to remember to run colima start to bring the virtual machine back up, before you can use Docker again.
Importing your existing data?
Now that you have Colima up and running, you’ll have noticed that things look pretty sparse. This is because all the existing container images and volumes are still within Docker Desktop’s managed VM.
If this data is important to you, Docker provides a way to backup and restore containers, and also a way to migrate data volumes.
I decided to skip this step as my own use of Docker is for local development. Any data I have in Docker is regenerated automatically when I run my projects.
Cleanup

Assuming you got this far and you’re happy with Colima, you will probably want to send your old Docker environment to the Trash, otherwise the containers and volumes will stick around consuming valuable disk space.
You can use the following commands to tidy everything up:
# Remove old Docker data:
rm -rf /Users/${USER}/Library/Containers/com.docker.docker
# Remove the old Docker Desktop application:
# Note: If you installed it via Homebrew as a Cask,
# run `brew remove --cask docker` instead.
rm -rf /Applications/Docker.app
# Remove the old Docker configuration files:
sudo rm -rf /usr/local/lib/docker
rm -rf ~/.docker
Enjoy!


