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! 🍻