Run macOS inside Docker on Linux, with Wayland

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

Making it work on Wayland

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! šŸŽ‰

Want to leave a comment?

Join the discussion on Twitter or send me an email! šŸ’Œ
This post helped you? Buy me a coffee! šŸ»