Run macOS inside Docker on Linux, with Wayland
April 13, 2022
April 13, 2022
This is gonna be a short one. Thereās this fucking fantastic software called Docker-OSX that lets you run a macOS VM on Linux out of the box, just like that. āØ
Running macOS on a non-Apple hardware is already not a trivial task, even though OpenCore and the (also fucking fantastic) Dortania guide help greatly. Let alone running it inside a VM.
Docker-OSX is based on OSX-KVM as well as KVM-OpenCore, and provides a Docker container thatās preconfigured to run the macOS installer of your choice inside a KVM virtual machine thatās already set up to support macOS.
With some Docker volume mounts magic, it can show the KVM window directly on your X11 display, despite you not installing KVM on your main system and configuring anything. Sweet.
The commands to run various macOS versions are directly in the readme and work out of the box! Example for Monterey:
docker run -it \
--device /dev/kvm \
-p 50922:10022 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=${DISPLAY:-:0.0}" \
-e GENERATE_UNIQUE=true \
-e MASTER_PLIST_URL='https://raw.githubusercontent.com/sickcodes/osx-serial-generator/master/config-custom.plist' \
sickcodes/docker-osx:monterey
I recently moved to Wayland,
so setting DISPLAY=:0.0
and mount binding /tmp/.X11-unix
is not
gonna do much. š¬
At the time of writing, thereās no official instructions in the readme to run with Wayland, but the task turned out to be fairly easy!
Luckily Iām not the first one to try to do that, and thereās already two open issues on the topic! The second one in particular contains a solution, essentially replacing the X11-specific volume and environment variable by Wayland equivalents (which I would definitely not have guessed easily š).
Once adapted for Monterey, the command is the following:
docker run -it \
--device /dev/kvm \
-p 50922:10022 \
-e XDG_RUNTIME_DIR=/tmp \
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
-v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/tmp/$WAYLAND_DISPLAY \
-e GENERATE_UNIQUE=true \
-e MASTER_PLIST_URL='https://raw.githubusercontent.com/sickcodes/osx-serial-generator/master/config-custom.plist' \
sickcodes/docker-osx:monterey
The original comment specified a number of extra environment variables but they didnāt appear to be needed for me.
And thatās it! Happy hacking on macOS in a VM! š