Running amd64 docker images with Podman on Apple Silicon (M1)
tl;dr it works, scroll though and look for the code snippets
You might have heard about Docker (the company) changing the terms of use which effectively requires enterprise users to pay up. While I personally think that paying for critical infrastructure that supports your business is a good idea there was a considerable backlash among engineers and “alternative to docker” was the common them on HN front page for a few days.
And the most notable alternative is Podman.
What is Podman? Podman is a daemonless container engine for developing, managing, and running OCI Containers on your Linux System. Containers can either be run as root or in rootless mode. Simply put: alias docker=podman. More details here.
Podman on MacOS
Podman relies on Linux kernel in order to work so I fact it’s linux-only software. People have been running it in VMs for a while (like Docker it supports a remote server, which can be a VM). And recently VM support has become native in form of podman machine
commands which manage a VM for you. More here.
Podman on Apple Silicon
At the time of writing the instructions above don’t work on Apple Silicon machines (currently just M1 macs). Reason for that is that podman machine
relies on qemu
for virtualisation and qemu
does not (yet) have support for the M1 specifics of the Apple Virtualisation Framework. But it’s close. In fact there is already a patch out there, just not yet part of the upstream distribution. simnalamburt has even packaged it for brew so you can install the patched qemu
and configure podman
to use it with a one liner.
|
|
Full instructions here. Do read through the source, there is not much magic going on.
Now we can configure our machine
|
|
Should be Currently running
. Let’s run something
|
|
Running amd64 images
What’s not obvious is that currently we only have support for running ARM images. Unlike Docker For Mac which can transparently run both. Let’s see what happens if you try to run something that does not have native ARM support.
|
|
Luckily we can fix that, we can teach our VM how to run this format of executables by using qemu-user-static
|
|
And after a few moments to reboot the VM
|
|
Liftoff! (mind the x86_64
)
How does it work?
QEMU is multiple things, it powers our podman machine
VM but it can also run inside this VM in a mode called User-mode emulation
. From the home-page
Run programs for another Linux/BSD target, on any supported architecture
In our case emulating an amd64 CPU on an ARM CPU (inside a VM!). Why user-mode? Because it’s not full emulation; it’s not emulating a kernel like a full VM but passing through syscalls to the regular kernel (in our case the VM).
This is different from the podman machine
VM which is not emulated but virtualised. Instructions run natively on the CPU with hardware support for sandboxing it away from the host. This is why patches for Apple’s Virtualisation Framework are needed for the (host) qemu.
How about performance? Just like with docker. Good performance for native images, and a penalty for running emulated images. IO should still be okay since it’s handled by the virtual kernel but CPU-bound workloads slow down a lot (up to 50x in my benchmarks). Should be good enough for development as long as you’re not compiling big stuff.
What’s that rpm-ostree
stuff? podman machine
uses Fedora CoreOS which is based off a baked image with “layered packages” instead of a more traditional package management. More here.
Last modified on 2021-09-12
Previous Trying out PrometheusNext Trying Out Remix