2020-06-05 13:41:37 -05:00
#!/usr/bin/docker
2020-06-04 13:31:47 -05:00
# ____ __ ____ ______ __
# / __ \____ _____/ /_____ _____/ __ \/ ___/ |/ /
2021-01-02 05:55:00 -06:00
# / / / / __ \/ ___/ //_/ _ \/ ___/ / / /\__ \| /
# / /_/ / /_/ / /__/ ,< / __/ / / /_/ /___/ / |
# /_____/\____/\___/_/|_|\___/_/ \____//____/_/|_|
#
2020-06-14 23:33:29 -05:00
# Repo: https://github.com/sickcodes/Docker-OSX/
2020-06-04 13:31:47 -05:00
# Title: Mac on Docker (Docker-OSX)
2021-01-02 05:55:00 -06:00
# Author: Sick.Codes https://sick.codes/
2021-02-25 08:03:06 -06:00
# Version: 3.2
2020-06-14 23:33:29 -05:00
# License: GPLv3+
2021-01-02 05:55:00 -06:00
#
2020-06-14 23:33:29 -05:00
# All credits for OSX-KVM and the rest at @Kholia's repo: https://github.com/kholia/osx-kvm
2021-01-02 05:55:00 -06:00
# OpenCore support go to https://github.com/Leoyzen/KVM-Opencore
2020-06-04 15:25:29 -05:00
# and https://github.com/thenickdude/KVM-Opencore/
2021-01-02 05:55:00 -06:00
#
2020-06-04 13:31:47 -05:00
# This Dockerfile automates the installation of Docker-OSX
2020-06-14 23:33:29 -05: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.
2021-01-02 05:55:00 -06:00
#
2020-06-04 13:31:47 -05:00
# Build:
#
# docker build -t docker-osx .
2020-06-14 23:33:29 -05:00
# docker build -t docker-osx --build-arg VERSION=10.15.5 --build-arg SIZE=200G .
2021-01-02 05:55:00 -06:00
#
2020-06-14 23:33:29 -05:00
# Basic Run:
#
2021-01-02 05:55:00 -06:00
# docker run --device /dev/kvm --device /dev/snd -v /tmp/.X11-unix:/tmp/.X11-unix -e "DISPLAY=${DISPLAY:-:0.0}" sickcodes/docker-osx:latest
2020-06-14 23:33:29 -05:00
#
# Run with SSH:
2021-01-02 05:55:00 -06:00
#
2020-11-13 02:34:40 -06:00
# docker run --device /dev/kvm --device /dev/snd -e RAM=6 -p 50922:10022 -v /tmp/.X11-unix:/tmp/.X11-unix -e "DISPLAY=${DISPLAY:-:0.0}" sickcodes/docker-osx:latest
2020-06-14 23:33:29 -05:00
# # ssh fullname@localhost -p 50922
2021-01-02 05:55:00 -06:00
#
2020-06-14 23:33:29 -05:00
# Optargs:
2021-01-02 05:55:00 -06:00
#
2021-01-24 06:47:19 -06:00
# -v $PWD/disk.img:/image
# -e SIZE=200G
# -e VERSION=10.15.6
# -e RAM=5
# -e SMP=4
# -e CORES=4
# -e EXTRA=
# -e INTERNAL_SSH_PORT=10022
2021-02-07 11:27:02 -06:00
# -e MAC_ADDRESS=
2020-06-14 23:33:29 -05:00
#
# 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
2020-06-04 13:31:47 -05:00
2021-02-21 00:38:27 -06:00
FROM archlinux:base-devel
2020-06-04 13:31:47 -05:00
2021-02-25 22:22:56 -06:00
MAINTAINER 'https://twitter.com/sickcodes' <https://sick.codes>
2020-06-04 13:31:47 -05:00
2020-12-31 04:30:53 -06:00
SHELL [ "/bin/bash" , "-c" ]
2020-06-14 23:33:29 -05:00
# change disk size here or add during build, e.g. --build-arg VERSION=10.14.5 --build-arg SIZE=50G
2021-01-24 07:06:37 -06:00
ARG SIZE = 200G
ARG VERSION = 10 .15.6
2020-06-04 13:31:47 -05:00
2021-01-24 06:47:19 -06:00
# OPTIONAL: Arch Linux server mirrors for super fast builds
# set RANKMIRRORS to any value other that nothing, e.g. -e RANKMIRRORS=true
ARG RANKMIRRORS
2021-01-05 04:03:25 -06:00
ARG MIRROR_COUNTRY = US
ARG MIRROR_COUNT = 10
2021-02-12 12:11:48 -06:00
2021-02-12 09:50:11 -06:00
# TEMP-FIX for pacman issue
2021-02-12 12:11:48 -06:00
RUN patched_glibc = glibc-linux4-2.33-4-x86_64.pkg.tar.zst \
2021-02-21 00:38:27 -06:00
&& curl -LO " https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/ ${ patched_glibc } " \
&& bsdtar -C / -xvf " ${ patched_glibc } " || echo "Everything is fine."
2021-02-12 09:50:11 -06:00
# TEMP-FIX for pacman issue
2021-02-12 12:11:48 -06:00
2021-02-07 11:59:24 -06:00
RUN if [ [ " ${ RANKMIRRORS } " ] ] ; then \
{ pacman -Sy wget --noconfirm || pacman -Syu wget --noconfirm ; } \
; wget -O ./rankmirrors "https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/rankmirrors" \
; wget -O- " https://www.archlinux.org/mirrorlist/?country= ${ MIRROR_COUNTRY :- US } &protocol=https&use_mirror_status=on " \
| sed -e 's/^#Server/Server/' -e '/^#/d' \
| head -n " $(( ${ MIRROR_COUNT :- 10 } + 1 )) " \
| bash ./rankmirrors --verbose --max-time 5 - > /etc/pacman.d/mirrorlist \
&& tee -a /etc/pacman.d/mirrorlist <<< 'Server = http://mirrors.evowise.com/archlinux/$repo/os/$arch' \
&& tee -a /etc/pacman.d/mirrorlist <<< 'Server = http://mirror.rackspace.com/archlinux/$repo/os/$arch' \
&& tee -a /etc/pacman.d/mirrorlist <<< 'Server = https://mirror.rackspace.com/archlinux/$repo/os/$arch' \
&& cat /etc/pacman.d/mirrorlist \
; fi
2021-01-05 04:03:25 -06:00
2020-06-14 23:33:29 -05:00
# This fails on hub.docker.com, useful for debugging in cloud
2020-06-04 17:17:01 -05:00
# RUN [[ $(egrep -c '(svm|vmx)' /proc/cpuinfo) -gt 0 ]] || { echo KVM not possible on this host && exit 1; }
2020-06-04 13:31:47 -05:00
2021-02-21 00:38:27 -06:00
# RUN tee -a /etc/pacman.conf <<< '[community-testing]' \
# && tee -a /etc/pacman.conf <<< 'Include = /etc/pacman.d/mirrorlist'
2020-06-04 13:31:47 -05:00
2021-02-23 23:29:17 -06:00
RUN pacman -Syu git zip vim nano alsa-utils openssh --noconfirm \
2020-10-05 03:01:45 -05:00
&& ln -s /bin/vim /bin/vi \
2020-06-18 08:30:02 -05: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 13:31:47 -05:00
2021-02-21 00:38:27 -06:00
# TEMP-FIX for pacman issue
RUN patched_glibc = glibc-linux4-2.33-4-x86_64.pkg.tar.zst \
&& curl -LO " https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/ ${ patched_glibc } " \
&& bsdtar -C / -xvf " ${ patched_glibc } " || echo "Everything is fine."
# TEMP-FIX for pacman issue
2020-06-14 23:33:29 -05:00
# allow ssh to container
2020-12-12 01:46:56 -06:00
RUN mkdir -m 700 /root/.ssh
2020-06-14 23:33:29 -05:00
WORKDIR /root/.ssh
2020-06-18 08:30:02 -05:00
RUN touch authorized_keys \
&& chmod 644 authorized_keys
2020-06-14 23:33:29 -05:00
WORKDIR /etc/ssh
2020-06-18 08:30:02 -05: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-14 23:33:29 -05:00
2020-06-04 13:31:47 -05:00
USER arch
2020-06-14 23:33:29 -05:00
# download OSX-KVM
2020-12-16 10:57:22 -06:00
RUN git clone --depth 1 https://github.com/kholia/OSX-KVM.git /home/arch/OSX-KVM
2020-06-04 13:31:47 -05:00
2020-06-14 23:33:29 -05:00
# enable ssh
# docker exec .... ./enable-ssh.sh
USER arch
2020-09-25 14:08:18 -05:00
WORKDIR /home/arch/OSX-KVM
2020-06-18 08:30:02 -05: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 08:42:16 -05:00
&& tee -a enable-ssh.sh <<< 'nohup sudo /usr/bin/sshd -D &'
2020-06-14 23:33:29 -05: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.
2021-01-05 07:15:44 -06:00
# RUN yes | sudo pacman -Syu qemu libvirt dnsmasq virt-manager bridge-utils edk2-ovmf netctl libvirt-dbus --overwrite --noconfirm
2021-01-24 06:47:19 -06:00
RUN yes | sudo pacman -Syu qemu libvirt dnsmasq virt-manager bridge-utils openresolv jack ebtables edk2-ovmf netctl libvirt-dbus --overwrite --noconfirm \
2021-02-07 11:59:24 -06:00
&& yes | sudo pacman -Scc
2021-01-05 07:15:44 -06:00
2021-02-21 00:38:27 -06:00
# TEMP-FIX for pacman issue
RUN patched_glibc = glibc-linux4-2.33-4-x86_64.pkg.tar.zst \
&& curl -LO " https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/ ${ patched_glibc } " \
&& bsdtar -C / -xvf " ${ patched_glibc } " || echo "Everything is fine."
# TEMP-FIX for pacman issue
2020-09-20 05:36:45 -05:00
# RUN sudo systemctl enable libvirtd.service
# RUN sudo systemctl enable virtlogd.service
2021-01-05 07:15:44 -06:00
WORKDIR /home/arch/OSX-KVM
2020-09-20 05:36:45 -05:00
2021-01-05 07:15:44 -06:00
RUN python fetch-macOS.py --version " ${ VERSION } " \
&& qemu-img convert BaseSystem.dmg -O qcow2 -p -c BaseSystem.img \
&& qemu-img create -f qcow2 mac_hdd_ng.img " ${ SIZE } " \
&& rm -f BaseSystem.dmg
2020-09-20 05:36:45 -05:00
2020-06-14 23:33:29 -05:00
# > Launch.sh
# > Docker-OSX.xml
2020-09-25 14:08:18 -05:00
WORKDIR /home/arch/OSX-KVM
2021-02-25 02:52:56 -06:00
ARG LINUX = true
# required to use libguestfs inside a docker container, to create bootdisks for docker-osx on-the-fly
RUN if [ [ " ${ LINUX } " = = true ] ] ; then \
sudo pacman -Syu linux libguestfs --noconfirm \
&& patched_glibc = glibc-linux4-2.33-4-x86_64.pkg.tar.zst \
&& curl -LO " https://raw.githubusercontent.com/sickcodes/Docker-OSX/master/ ${ patched_glibc } " \
&& bsdtar -C / -xvf " ${ patched_glibc } " || echo "Everything is fine." \
; fi
2021-02-27 01:05:22 -06:00
# optional --build-arg to change branches for testing
ARG BRANCH = master
ARG REPO = 'https://github.com/sickcodes/Docker-OSX.git'
RUN git clone --branch " ${ BRANCH } " " ${ REPO } "
2021-02-25 02:52:56 -06:00
2020-06-18 08:30:02 -05:00
RUN touch Launch.sh \
&& chmod +x ./Launch.sh \
2020-09-20 04:04:35 -05:00
&& tee -a Launch.sh <<< '#!/bin/sh' \
&& tee -a Launch.sh <<< 'set -eu' \
2020-09-20 04:31:44 -05: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 04:05:40 -05: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 \' \
2021-02-25 02:52:56 -06:00
&& tee -a Launch.sh <<< '-smp ${CPU_STRING:-${SMP:-4},cores=${CORES:-4}} \' \
2020-06-18 08:30:02 -05: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 05:36:45 -05:00
&& tee -a Launch.sh <<< '-drive if=pflash,format=raw,file=/home/arch/OSX-KVM/OVMF_VARS-1024x768.fd \' \
2020-06-18 08:30:02 -05:00
&& tee -a Launch.sh <<< '-smbios type=2 \' \
2020-09-20 04:14:24 -05:00
&& tee -a Launch.sh <<< '-audiodev ${AUDIO_DRIVER:-alsa},id=hda -device ich9-intel-hda -device hda-duplex,audiodev=hda \' \
2020-06-18 08:30:02 -05:00
&& tee -a Launch.sh <<< '-device ich9-ahci,id=sata \' \
2021-02-25 02:52:56 -06:00
&& tee -a Launch.sh <<< '-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=${BOOTDISK:-/home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2} \' \
2020-06-18 08:30:02 -05:00
&& 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 05:36:45 -05:00
&& tee -a Launch.sh <<< '-drive id=InstallMedia,if=none,file=/home/arch/OSX-KVM/BaseSystem.img,format=qcow2 \' \
2021-01-07 14:12:35 -06:00
&& tee -a Launch.sh <<< '-drive id=MacHDD,if=none,file=${IMAGE_PATH:-/home/arch/OSX-KVM/mac_hdd_ng.img},format=qcow2 \' \
2020-06-18 08:30:02 -05:00
&& tee -a Launch.sh <<< '-device ide-hd,bus=sata.4,drive=MacHDD \' \
2021-02-08 16:05:18 -06:00
&& tee -a Launch.sh <<< '-netdev user,id=net0,hostfwd=tcp::${INTERNAL_SSH_PORT:-10022}-:22,hostfwd=tcp::${SCREEN_SHARE_PORT:-5900}-:5900, \' \
2021-02-08 16:08:25 -06:00
&& tee -a Launch.sh <<< '-device ${NETWORKING:-e1000-82545em},netdev=net0,id=net0,mac=${MAC_ADDRESS:-52:54:00:09:49:17} \' \
2020-06-18 08:30:02 -05:00
&& tee -a Launch.sh <<< '-monitor stdio \' \
&& tee -a Launch.sh <<< '-vga vmware \' \
2020-09-20 04:04:19 -05:00
&& tee -a Launch.sh <<< '${EXTRA:-}'
2020-06-04 13:31:47 -05:00
2020-10-06 12:12:45 -05:00
# docker exec containerid mv ./Launch-nopicker.sh ./Launch.sh
2021-02-25 08:03:06 -06:00
# This is now a legacy command.
# You can use -e BOOTDISK=/bootdisk with -v ./bootdisk.img:/bootdisk
2020-10-06 12:12:45 -05:00
RUN grep -v InstallMedia ./Launch.sh > ./Launch-nopicker.sh \
&& chmod +x ./Launch-nopicker.sh \
&& sed -i -e s/OpenCore\. qcow2/OpenCore\- nopicker\. qcow2/ ./Launch-nopicker.sh
2021-02-07 11:27:02 -06:00
USER arch
2020-06-04 13:31:47 -05:00
ENV USER arch
2020-06-14 23:33:29 -05:00
2021-02-25 12:16:24 -06:00
ENV BOOTDISK = /home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2
2021-01-24 07:06:37 -06:00
ENV DISPLAY = :0.0
2020-09-20 04:18:40 -05:00
2021-02-25 12:16:24 -06:00
ENV ENV = /env
2021-01-07 14:12:35 -06:00
ENV IMAGE_PATH = /home/arch/OSX-KVM/mac_hdd_ng.img
2021-02-08 16:05:18 -06:00
ENV NETWORKING = e1000-82545em
# ENV NETWORKING=vmxnet3
2021-02-21 05:02:41 -06:00
ENV NOPICKER = false
2021-02-25 08:03:06 -06:00
ENV UNIQUE = false
2021-02-25 12:16:24 -06:00
# Boolean for generating a bootdisk with new serials.
2021-02-25 08:03:06 -06:00
2021-01-26 15:25:45 -06:00
VOLUME [ "/tmp/.X11-unix" ]
2021-02-25 08:03:06 -06:00
# check if /image is a disk image or a directory. This allows you to optionally use -v disk.img:/image
# NOPICKER is used to skip the disk selection screen
# GENERATE_UNIQUE is used to generate serial numbers on boot.
# /env is a file that you can generate and save using -v source.sh:/env
# the env file is a file that you can carry to the next container which will supply the serials numbers.
# GENERATE_SPECIFIC is used to either accept the env serial numbers OR you can supply using:
# -e DEVICE_MODEL="iMacPro1,1" \
# -e SERIAL="C02TW0WAHX87" \
# -e BOARD_SERIAL="C027251024NJG36UE" \
# -e UUID="5CCB366D-9118-4C61-A00A-E5BAF3BED451" \
# -e MAC_ADDRESS="A8:5C:2C:9A:46:2F" \
# the output will be /bootdisk.
# /bootdisk is a useful persistent place to store the 15Mb serial number bootdisk.
# if you don't set any of the above:
# the default serial numbers are already contained in ./OpenCore-Catalina/OpenCore.qcow2
# And the default serial numbers
2021-02-26 00:42:57 -06:00
CMD sudo chown -R $( id -u) :$( id -g) /dev/kvm /dev/snd " ${ IMAGE_PATH } " " ${ BOOTDISK } " " ${ ENV } " 2>/dev/null || true \
2021-02-25 09:17:52 -06:00
; case " $( file --brief /image) " in \
2021-02-25 08:03:06 -06:00
QEMU\ QCOW2\ Image* ) export IMAGE_PATH = /image \
; ; \
directory* ) export IMAGE_PATH = /home/arch/OSX-KVM/mac_hdd_ng.img \
; ; \
2021-01-24 06:47:19 -06:00
esac \
2021-02-25 23:49:40 -06:00
; [ [ " ${ NOPICKER } " = = true ] ] && { \
sed -i '/^.*InstallMedia.*/d' Launch.sh \
&& export BOOTDISK = /home/arch/OSX-KVM/OpenCore-Catalina/OpenCore-nopicker.qcow2 \
; } \
2021-02-25 23:26:35 -06:00
; [ [ " ${ GENERATE_UNIQUE } " = = true ] ] && { \
./Docker-OSX/custom/generate-unique-machine-values.sh \
2021-02-25 08:03:06 -06:00
--count 1 \
--tsv ./serial.tsv \
--bootdisks \
2021-02-25 23:26:35 -06:00
--output-bootdisk " ${ BOOTDISK :- /home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2 } " \
2021-02-26 03:25:40 -06:00
--output-env " ${ ENV : =/env } " || exit 1 \
2021-02-25 23:26:35 -06:00
; } \
; [ [ " ${ GENERATE_SPECIFIC } " = = true ] ] && { \
2021-02-25 23:30:09 -06:00
source " ${ ENV : =/env } " \
2021-02-25 08:03:06 -06:00
|| ./Docker-OSX/custom/generate-specific-bootdisk.sh \
--model " ${ DEVICE_MODEL } " \
--serial " ${ SERIAL } " \
--board-serial " ${ BOARD_SERIAL } " \
--uuid " ${ UUID } " \
--mac-address " ${ MAC_ADDRESS } " \
2021-02-26 03:25:40 -06:00
--output-bootdisk " ${ BOOTDISK :- /home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2 } " || exit 1 \
2021-02-25 23:26:35 -06:00
; } \
2021-02-25 08:03:06 -06:00
; case " $( file --brief /bootdisk) " in \
QEMU\ QCOW2\ Image* ) export BOOTDISK = /bootdisk \
; ; \
directory* ) export BOOTDISK = /home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2 \
; ; \
esac \
2021-01-24 06:47:19 -06:00
; ./enable-ssh.sh && envsubst < ./Launch.sh | bash
2020-06-04 13:31:47 -05:00
2020-06-14 23:33:29 -05: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