Using sickcodes/Docker-OSX on Arch Linux Simplified

Benjamin Sautner
5 min readNov 17, 2021

--

I’m setting up my Arch Linux box to experiment with Android and iOS Development with KMM. I don’t want to switch between machines and while I VNC into a headless Windows box to use things like Fusion 360, I couldn’t get VNC to be responsive enough to code on a headless mac. So getting OSX on a docker image seemed the right direction since you need a mac to use the Android Studio KMM Plugin.

This is a great project but since I’m rather new to Docker it took me a couple tries and had to learn a few things. https://github.com/sickcodes/Docker-OSX

This assumes you went through the pre-steps in that site and you know docker is working on your system. This also only covers Monterey and I gloss over things covered on their video.

What I learned is docker will always create a new image when you run it. So the first step is actually creating.

Everything here is covered in a video by @SickCodes on the above site, the purpose of this writeup is to give a direct path to working Montery system.

Step 1. Create your mac image:

This will launch a mac os installer — it will not launch you into Montery.

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

Follow the instructions in the tutorial to erase the largest hard drive and install the system.

After the install finishes the system goes through a shutdown sequence. This is the first source of confusion for me since i thought I’d just reboot into Monterey, this is actually the completion of the creation of a mac image. You now can close this window.

This is a good thing, image creation is complete, close QEMU window.

Step 2.

Switch to root and find the new mac image and copy it somewhere convenient.

$ sudo su
$ cd /var/lib/docker
$ find -name mac_hdd_ng.img | xargs ls -lhta

At the top you should see a recently created .img file that’s large. Copy that somewhere convenient and make your normal user the owner

I created a folder called /mnt/docker out of personal preference but you can keep your imgs anywhere. Also in this example my user id is ben

$ sudo mkdir /mnt/docker
$ sudo chown ben /mnt/docker
$ cp ./overlay2/77b74567b2.../diff/home/arch/OSX-KVM/mac_hdd_ng.img /mnt/docker
$ chown ben /mnt/docker/mac_hdd_ng.img
$ cd /mnt/docker
$ exit #exit root session

Step 3.

We’re now going to launch that image. Note every time you run this command you get a new image so after this you need to run it using the docker start command.

docker run -it \
--device /dev/kvm \
-p 50922:10022 \
-v "${PWD}/mac_hdd_ng.img:/image" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=${DISPLAY:-:0.0}" \
-e MASTER_PLIST_URL=https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/custom/config-nopicker-custom.plist \
sickcodes/docker-osx:naked

You’re now going to go through a long setup. You should see the apple symbol and a 30 minute setup. You’ll then see a lot of command line output and it’ll appear to reboot once, show another apple loading screen and finally land on another shutdown screen. If you run the command above again you’ll just end up starting this over. The trick is when it finished you need to run the docker image this creates. Once you see the system shutdown, it’s safe to close this QEMU window.

Step 4.

Run this command to get the container id of the docker session that just closed. You should see it at the top as something that was created recently, then start that container:

$docker ps -a
$docker start 7d3f9f6c2cbb

Don’t panic as you see another long session, apple progress and another reboot. You’ll use this container every time if you want to re-use changes you make to this image. You’ll go through the normal mac setup and eventually land on your new desktop.

The performance of this docker is pretty slow so on my TODO list is to figure out how to add more ram and cores and run the system optimization suggestions on the repo.

Many thanks to Sick Codes for this awesome docker setup!

Next Steps…

Adding Ram

The trick is to copy the config file out of your docker dir using a json formatter and then back in so you can edit it. This issues shows how:

Using a GPU

Giving docker access to a GPU helps get this image to the point i can run xcode and android studio: https://wiki.archlinux.org/title/docker#With_NVIDIA_Container_Toolkit_(recommended)

This is the final run command I use to launch a mac with 24 gigs of ram and access to the host gpu:

docker run -it \
-m 24g \
--cpus="6.0" \
--gpus all \
--device /dev/nvidia0 \
--device /dev/nvidia-uvm \
--device /dev/nvidia-uvm-tools \
--device /dev/nvidiactl \
--device /dev/kvm \
-p 50922:10022 \
-v "${PWD}/mac_hdd_ng.img:/image" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=${DISPLAY:-:0.0}" \
-e MASTER_PLIST_URL=https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/custom/config-nopicker-custom.plist \
sickcodes/docker-osx:naked

cheers!

--

--

Benjamin Sautner

I am a Distinguished Engineer with a passion for mobile and embedded system design. Opinions and information on this site are my own.