Tutorial

Running x86_64-based containers on Mac computers with an Apple silicon (M1) processor

Configuring Podman VMs to run both x86_64-based and AArch64-based containers

By

Piers Walter,

Francesco Rinaldi

Several developer resources are developed in x86_64 containers. So, developers need to be able to run x86_64 containers on newer Mac computers that are built with an Apple Silicon (M1) processor, which is an ARM64 architecture. In this tutorial, we will explore how to configure Podman to be able to run these x86-64 containers on these ARM64 processors.

The process involves creating an x86_64-based VM for Podman (X86_64 image of Fedora CoreOS) to run its images on, instead of the AArch64 (ARM64) used by default. This solution does not affect the current Podman VM setup since it is possible to switch between the different VM architectures, running images on the AArch64 VM when performance matters or on the x86_64 VM when these types of compatibility issues occur.

Prerequisites

  • A Mac computer with an Apple Silicon (M1) processor
  • Homebrew
  • Podman 4.4.2 for x86 (if you are installing this tool without Rosetta the installation could fail on your M1 Mac computer)

The instructions in this tutorial are based on Podman version 4.4.2 installed on macOS 12.5. This tutorial has been tested with the specified Podman version and it does not guarantee that this solution will work with future versions.

Steps

Some container images are not currently compiled natively for AArch64. This is not always obvious until you encounter an unexpected runtime failure due to processor incompatibility.

These instructions detail how to get container images running on M1 ARM64-based Macs.

Step 1. Create the podman VM

If you currently have a podman VM running, stop it with this command:

podman machine stop

Then, make sure your QEMU is running the latest version by running this command:

brew upgrade qemu

Issue the command qemu-system-x86_64 --version to verify the QEMU emulator is version 7.0.0 or higher.

Now you are ready to create a podman VM using the x86_64 image of Fedora CoreOS. Download the current version of the Fedora CoreOS QEMU (qcow2.xz) image. Unzip it, and then run the following command:

podman machine init --image-path ~/yourFedoraImageFolder/fedora-coreos-<currentVersion>-qemu.x86_64.qcow2.xz intel

Don't start your VM yet, it won't work!

Now, you have a podman VM called intel which is set to use the x86_64 image. Next, you need to configure the machine JSON file because podman assumes you're running the AArch64 image rather than the x86_64 image.

Navigate to the ~/.config/containers/podman/machine/qemu directory. Open the file called intel.json in an editor to change the QEMU command line options. Before making any changes to this file, back up this file.

Delete the following lines from the JSON file which are used for defining the HVF QEMU accelerator, which is supported on x86 chips only:

  "-machine",
  "q35,accel=hvf:tcg",
  "-cpu",
  "host",

The podman configuration file is now correctly set up to launch the podman VM.

You can now switch between the two podman VMs. To switch the default podman VM to the new x86_64 one, use this command:

podman system connection default intel

To switch back to the normal podman VM, use this command:

podman system connection default podman-machine-default

Step 2. Run your container image

Starting the x86_64 podman VM takes a few minutes because it's emulating x86_64 rather than running natively. If you are not having compatibility issues with your containers, you should definitely use the podman-machine-default podman VM.

To start your new x86_64 VM, run this command:

podman machine start intel

Now, you can run an x86_64-based container image in emulation mode successfully. This process can take up to 15 minutes since the machine will run without an accelerator.

Summary

In this tutorial, you learned how to configure Podman to be able to run x86-64 containers on newer Mac computers that are built with an Apple Silicon (M1) processor, which is an ARM64 architecture.