How to setup Docker on M-series Mac to run x86_64 images

· 1 min read

Newer MacOS laptops have M-series processors which are arm64, not x86/64 like their Intel predecessors. Some docker images do not have an arm64 image yet released to public registries (I’m looking at you mcr.microsoft.com/mssql/server:2019-latest) and other tooling might be better utilized through docker (donet prior to v7 doesn’t have a native arm64 binary).

Instructions

Run your container

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=VeryStr0ngP@ssw0rd" -p 1433:1433 --name sql --hostname sql-server --platform linux/amd64 -d mcr.microsoft.com/mssql/server:2019-latest

Set up your shell to look and feel like docker

alias docker='lima nerdctl'
alias docker-compose='lima nerdctl compose'

Start the VM

limactl start default

Create a VM with the required parameters (use default to make things easier)

vmType: "vz"
rosetta:
  # Enable Rosetta for Linux.
  # Hint: try `softwareupdate --install-rosetta` if Lima gets stuck at `Installing rosetta...`
  enabled: true
  # Register rosetta to /proc/sys/fs/binfmt_misc
  binfmt: true

Install Lima

brew install lima

ℹ️
This uses the Mac OS’s Virtual Machine Service aka Rosetta 2 to translate an amd64 instruction set into arm64 commands
ℹ️
This uses containerd as the container runtime but docker or podman may also work. Lima has many templates available if you want to try and use those as the basis, adding the above config keys.

Troubleshooting

I have observed a propensity for the VM to become unresponsive, at least on Ventura. This can be checked a few ways:

  • Virtual Machine Service uses > 100% cpu when you are not running anything intensive
  • Using lima commands fails to connect to the VM (hangs) ex:lima nerdctl ps

This usually happens after a sleep/wake cycle. The only way I’ve found to fix it is to completely remove the vm via limactl factory-reset default and recreate the vm, which only takes limactl start default as the config still exists. Some times that can fail to create a clean VM so you may have to redo it several times.