2020-06-05 18:41:37 +00:00
#!/usr/bin/docker
2020-06-04 18:31:47 +00:00
# ____ __ ____ ______ __
# / __ \____ _____/ /_____ _____/ __ \/ ___/ |/ /
# / / / / __ \/ ___/ //_/ _ \/ ___/ / / /\__ \| /
# / /_/ / /_/ / /__/ ,< / __/ / / /_/ /___/ / |
# /_____/\____/\___/_/|_|\___/_/ \____//____/_/|_|
#
2020-06-15 04:33:29 +00:00
# Repo: https://github.com/sickcodes/Docker-OSX/
2020-06-04 18:31:47 +00:00
# Title: Mac on Docker (Docker-OSX)
2020-06-15 04:33:29 +00:00
# Author: Sick.Codes https://sick.codes/
2020-09-20 08:16:44 +00:00
# Version: 2.5
2020-06-15 04:33:29 +00:00
# License: GPLv3+
2020-06-04 18:31:47 +00:00
#
2020-06-15 04:33:29 +00:00
# All credits for OSX-KVM and the rest at @Kholia's repo: https://github.com/kholia/osx-kvm
2020-06-04 20:25:29 +00:00
# OpenCore support go to https://github.com/Leoyzen/KVM-Opencore
# and https://github.com/thenickdude/KVM-Opencore/
2020-06-04 18:31:47 +00:00
#
# This Dockerfile automates the installation of Docker-OSX
2020-06-15 04:33:29 +00:00
# It will build a 200GB container. You can change the size using build arguments.
# This Dockerfile builds on top of the work done by Dhiru Kholia, and many others.
2020-06-04 18:31:47 +00:00
#
# Build:
#
# docker build -t docker-osx .
2020-06-15 04:33:29 +00:00
# docker build -t docker-osx --build-arg VERSION=10.15.5 --build-arg SIZE=200G .
#
# Basic Run:
2020-06-04 18:31:47 +00:00
#
2020-06-15 04:33:29 +00:00
# docker run --privileged -e "DISPLAY=${DISPLAY:-:0.0}" -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx
#
#
# Run with SSH:
#
#
# docker run -e RAM=6 --privileged -p 50922:10022 -e "DISPLAY=${DISPLAY:-:0.0}" -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx:latest
# # ssh fullname@localhost -p 50922
#
# Optargs:
2020-06-04 18:31:47 +00:00
#
2020-06-15 04:33:29 +00:00
# SIZE=200G
2020-08-23 19:39:47 +00:00
# VERSION=10.15.6
2020-06-15 04:33:29 +00:00
# ENV RAM=5
# ENV SMP=4
# ENV CORES=4
# ENV EXTRA=
# ENV INTERNAL_SSH_PORT=10022
#
# Extra QEMU args:
#
# docker run ... -e EXTRA="-usb -device usb-host,hostbus=1,hostaddr=8" ...
# # you will also need to pass the device to the container
#
#
# Other permissions:
#
# docker run --privileged --net host -e "DISPLAY=${DISPLAY:-:0.0}" -e RAM=6 --cap-add=ALL -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev:/dev -v /lib/modules:/lib/modules -v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock docker-osx:latest
2020-06-04 18:31:47 +00:00
FROM archlinux:latest
MAINTAINER 'https://sick.codes' <https://sick.codes>
2020-06-15 04:33:29 +00:00
# change disk size here or add during build, e.g. --build-arg VERSION=10.14.5 --build-arg SIZE=50G
ARG SIZE = 200G
2020-08-23 19:39:47 +00:00
ARG VERSION = 10 .15.6
2020-06-04 18:31:47 +00:00
2020-06-15 04:33:29 +00:00
# This fails on hub.docker.com, useful for debugging in cloud
2020-06-04 22:17:01 +00:00
# RUN [[ $(egrep -c '(svm|vmx)' /proc/cpuinfo) -gt 0 ]] || { echo KVM not possible on this host && exit 1; }
2020-06-04 18:31:47 +00:00
WORKDIR /root
2020-06-18 13:30:02 +00:00
RUN tee -a /etc/pacman.conf <<< '[community-testing]' \
&& tee -a /etc/pacman.conf <<< 'Include = /etc/pacman.d/mirrorlist'
2020-06-04 18:31:47 +00:00
2020-06-18 13:30:02 +00:00
RUN pacman -Syu --noconfirm \
&& pacman -S sudo git make automake gcc python go autoconf cmake pkgconf alsa-utils fakeroot --noconfirm \
2020-09-20 10:05:02 +00:00
&& yes | pacman -Scc \
2020-06-18 13:30:02 +00:00
&& useradd arch -p arch \
&& tee -a /etc/sudoers <<< 'arch ALL=(ALL) NOPASSWD: ALL' \
&& mkdir /home/arch \
&& chown arch:arch /home/arch
2020-06-04 18:31:47 +00:00
2020-06-15 04:33:29 +00:00
# allow ssh to container
WORKDIR /root
2020-06-18 13:30:02 +00:00
RUN mkdir .ssh \
&& chmod 700 .ssh
2020-06-15 04:33:29 +00:00
WORKDIR /root/.ssh
2020-06-18 13:30:02 +00:00
RUN touch authorized_keys \
&& chmod 644 authorized_keys
2020-06-15 04:33:29 +00:00
WORKDIR /etc/ssh
2020-06-18 13:30:02 +00:00
RUN tee -a sshd_config <<< 'AllowTcpForwarding yes' \
&& tee -a sshd_config <<< 'PermitTunnel yes' \
&& tee -a sshd_config <<< 'X11Forwarding yes' \
&& tee -a sshd_config <<< 'PasswordAuthentication yes' \
&& tee -a sshd_config <<< 'PermitRootLogin yes' \
&& tee -a sshd_config <<< 'PubkeyAuthentication yes' \
&& tee -a sshd_config <<< 'HostKey /etc/ssh/ssh_host_rsa_key' \
&& tee -a sshd_config <<< 'HostKey /etc/ssh/ssh_host_ecdsa_key' \
&& tee -a sshd_config <<< 'HostKey /etc/ssh/ssh_host_ed25519_key'
2020-06-15 04:33:29 +00:00
2020-06-04 18:31:47 +00:00
USER arch
2020-06-15 04:33:29 +00:00
# download OSX-KVM
2020-06-04 18:31:47 +00:00
WORKDIR /home/arch
RUN git clone https://github.com/kholia/OSX-KVM.git
2020-06-15 04:33:29 +00:00
# enable ssh
# docker exec .... ./enable-ssh.sh
USER arch
2020-09-25 19:08:18 +00:00
WORKDIR /home/arch/OSX-KVM
2020-06-18 13:30:02 +00:00
RUN touch enable-ssh.sh \
&& chmod +x ./enable-ssh.sh \
&& tee -a enable-ssh.sh <<< '[[ -f /etc/ssh/ssh_host_rsa_key ]] || \' \
&& tee -a enable-ssh.sh <<< '[[ -f /etc/ssh/ssh_host_ed25519_key ]] || \' \
&& tee -a enable-ssh.sh <<< '[[ -f /etc/ssh/ssh_host_ed25519_key ]] || \' \
&& tee -a enable-ssh.sh <<< 'sudo /usr/bin/ssh-keygen -A' \
2020-06-18 13:42:16 +00:00
&& tee -a enable-ssh.sh <<< 'nohup sudo /usr/bin/sshd -D &'
2020-06-15 04:33:29 +00:00
# QEMU CONFIGURATOR
# set optional ram at runtime -e RAM=16
# set optional cores at runtime -e SMP=4 -e CORES=2
# add any additional commands in QEMU cli format -e EXTRA="-usb -device usb-host,hostbus=1,hostaddr=8"
# default env vars, RUNTIME ONLY, not for editing in build time.
2020-09-20 10:36:45 +00:00
RUN sudo pacman -Syu qemu libvirt dnsmasq virt-manager bridge-utils flex bison ebtables edk2-ovmf netctl libvirt-dbus libguestfs --noconfirm && yes | sudo pacman -Scc
# RUN sudo systemctl enable libvirtd.service
# RUN sudo systemctl enable virtlogd.service
2020-09-25 19:08:18 +00:00
WORKDIR /home/arch/OSX-KVM
2020-09-20 10:36:45 +00:00
RUN git clone https://github.com/corpnewt/gibMacOS.git
2020-09-25 19:08:18 +00:00
2020-09-20 10:36:45 +00:00
WORKDIR /home/arch/gibMacOS
# this command takes a while!
RUN perl -p -i -e 's/print("Succeeded:")/exit()/' ./gibMacOS.command \
&& { python gibMacOS.command -v " ${ VERSION } " -d || echo Done; } \
2020-09-25 19:08:18 +00:00
&& qemu-img convert /home/arch/OSX-KVM/gibMacOS/macOS\ Downloads/publicrelease/*/BaseSystem.dmg -O qcow2 -p -c /home/arch/OSX-KVM/BaseSystem.img \
&& qemu-img create -f qcow2 /home/arch/OSX-KVM/mac_hdd_ng.img " ${ SIZE } " \
&& rm /home/arch/OSX-KVM/gibMacOS/macOS\ Downloads/publicrelease/*/BaseSystem.dmg
2020-09-20 10:36:45 +00:00
2020-06-15 04:33:29 +00:00
# > Launch.sh
# > Docker-OSX.xml
2020-09-25 19:08:18 +00:00
WORKDIR /home/arch/OSX-KVM
2020-06-18 13:30:02 +00:00
RUN touch Launch.sh \
&& chmod +x ./Launch.sh \
2020-09-20 09:04:35 +00:00
&& tee -a Launch.sh <<< '#!/bin/sh' \
&& tee -a Launch.sh <<< 'set -eu' \
2020-09-20 09:31:44 +00:00
&& tee -a Launch.sh <<< 'sudo chown $(id -u):$(id -g) /dev/kvm 2>/dev/null || true' \
&& tee -a Launch.sh <<< 'sudo chown -R $(id -u):$(id -g) /dev/snd 2>/dev/null || true' \
2020-09-20 09:05:40 +00:00
&& tee -a Launch.sh <<< 'exec qemu-system-x86_64 -m ${RAM:-8}000 \' \
&& tee -a Launch.sh <<< '-cpu Penryn,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check \' \
&& tee -a Launch.sh <<< '-machine q35,accel=kvm:tcg \' \
2020-09-20 09:04:19 +00:00
&& tee -a Launch.sh <<< '-smp ${SMP:-4},cores=${CORES:-4} \' \
2020-06-18 13:30:02 +00:00
&& tee -a Launch.sh <<< '-usb -device usb-kbd -device usb-tablet \' \
&& tee -a Launch.sh <<< '-device isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal\(c\)AppleComputerInc \' \
&& tee -a Launch.sh <<< '-drive if=pflash,format=raw,readonly,file=/home/arch/OSX-KVM/OVMF_CODE.fd \' \
2020-09-20 10:36:45 +00:00
&& tee -a Launch.sh <<< '-drive if=pflash,format=raw,file=/home/arch/OSX-KVM/OVMF_VARS-1024x768.fd \' \
2020-06-18 13:30:02 +00:00
&& tee -a Launch.sh <<< '-smbios type=2 \' \
2020-09-20 09:14:24 +00:00
&& tee -a Launch.sh <<< '-audiodev ${AUDIO_DRIVER:-alsa},id=hda -device ich9-intel-hda -device hda-duplex,audiodev=hda \' \
2020-06-18 13:30:02 +00:00
&& tee -a Launch.sh <<< '-device ich9-ahci,id=sata \' \
&& tee -a Launch.sh <<< '-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=/home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2 \' \
&& tee -a Launch.sh <<< '-device ide-hd,bus=sata.2,drive=OpenCoreBoot \' \
&& tee -a Launch.sh <<< '-device ide-hd,bus=sata.3,drive=InstallMedia \' \
2020-09-20 10:36:45 +00:00
&& tee -a Launch.sh <<< '-drive id=InstallMedia,if=none,file=/home/arch/OSX-KVM/BaseSystem.img,format=qcow2 \' \
2020-06-18 13:30:02 +00:00
&& tee -a Launch.sh <<< '-drive id=MacHDD,if=none,file=/home/arch/OSX-KVM/mac_hdd_ng.img,format=qcow2 \' \
&& tee -a Launch.sh <<< '-device ide-hd,bus=sata.4,drive=MacHDD \' \
2020-09-20 09:04:19 +00:00
&& tee -a Launch.sh <<< '-netdev user,id=net0,hostfwd=tcp::${INTERNAL_SSH_PORT:-10022}-:22,hostfwd=tcp::${SCREEN_SHARE_PORT:-5900}-:5900, -device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:09:49:17 \' \
2020-06-18 13:30:02 +00:00
&& tee -a Launch.sh <<< '-monitor stdio \' \
&& tee -a Launch.sh <<< '-vga vmware \' \
2020-09-20 09:04:19 +00:00
&& tee -a Launch.sh <<< '${EXTRA:-}'
2020-06-04 18:31:47 +00:00
ENV USER arch
2020-06-15 04:33:29 +00:00
2020-09-20 09:18:40 +00:00
ENV DISPLAY = :0.0
2020-06-04 18:31:47 +00:00
USER arch
2020-09-25 19:03:23 +00:00
2020-06-04 18:31:47 +00:00
VOLUME [ "/tmp/.X11-unix" ]
2020-09-25 19:03:23 +00:00
WORKDIR /home/arch/OSX-KVM
2020-06-15 04:33:29 +00:00
CMD ./enable-ssh.sh && envsubst < ./Launch.sh | bash
2020-06-04 18:31:47 +00:00
2020-06-15 04:33:29 +00:00
# virt-manager mode: eta son
# CMD virsh define <(envsubst < Docker-OSX.xml) && virt-manager || virt-manager
# CMD virsh define <(envsubst < macOS-libvirt-Catalina.xml) && virt-manager || virt-manager