This guide offers a step by step tutorial on how to install macOS in a Docker container on a Gcore bare metal server. The main benefit of going with bare metal over a virtual machine is that bare metal doesnât require virtualization software, but rather uses hardware resources directly. As a result, you can get better performance from a Gcore bare-metal server than from a Gcore virtual machine.
You donât need much experience with bare metal and Docker administration to install macOS on bare metal with Ubuntu successfully. Just follow the recommendations and CLI commands we provide here!
When Should You Use macOS on Bare Metal with Ubuntu?
Installing macOS in a Docker container is a great way to run macOS on non-Apple hardware. It can be a great solution for developers who need to test their applications on macOS, but donât have access to an Apple computer. By following the steps in this guide, you can easily set up a macOS environment in Docker and start testing your applications.
How to Run Bare Metal and Install macOS
Step 1. Provision a Bare Metal Instance
First, you need to provision a bare metal instance by following a few simple steps:
- Log in to your Gcore Cloud account. If you donât have it yet, sign up.
- Go to Cloud and select Projects.
- Click Create project; fill in the Name field. Projects are groups of separate Cloud resources, and these groups are isolated from each other. The isolation gives you the ability to set user rights for each project.
- In your project, select Baremetal and click Create Baremetal Server.
- Set the following parameters when creating a new bare-metal instance:
- Region: Luxembourg-2.
- Image: Ubuntu 22.04.
- Flavor: 1x Intel Xeon E-2388 8C/16T 3.2 GHz / 64 GB / 2x 480GB SSD / 2x 1GbE.
- Network interfaces: Public IP.
- SSH Key: upload your public SSH key or generate a new one.
- Name: macos-server (or whatever you want.)
- Now youâve completed the set up, click Create Server. The server will appear in the âBaremetal Serversâ section. Wait until its âCreatingâ status changes to âPower on.â
Step 2. Connect to the Server and Update Ubuntu
Before installing macOS in Docker, make sure that the Ubuntu OS is up to date.
- Log in to the server by SSH using the following command:
ssh ubuntu@<your_public_ip_address>
For example:
ssh ubuntu@45.82.30.25
- Update Ubuntu:
ubuntu@macos-server:~$ sudo su root@macos-server:/home/ubuntu# apt update
Step 3. Install Necessary Components before Running the macOS Image
Before running the macOS image, you need to install the following additional components that will enable CPU virtualization on the Ubuntu server:
- qemu
- qemu-kvm
- libvirt-clients
- libvirt-daemon-system
- bridge-utils
- virt-manager
- docker.io
- xfce4
- xfce4-goodies
- tightvncserver
- To install these components, use the following command:
root@macos-server:/home/ubuntu# sudo apt install qemu qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager docker.io xfce4 xfce4-goodies tightvncserver
- Now you need to initialize the X11 display, also known as X. This is the software framework that provides a graphical user interface for Linux and other Unix-like operating systems.
Run VNCServer to initialize the X11 display:
root@macos-server:/home/ubuntu# vncserver :0 You will require a password to access your desktops. Password:
- If you experience an error with the âfixedâ font, use the following command:
root@macos-server:/home/ubuntu# apt-get --reinstall install xfonts-base root@macos-server:/home/ubuntu# vncserver :0
Hereâs what you should see:
root@macos-server:/home/ubuntu# vncserver :0 New 'X' desktop is macos-server:0 Creating default startup script /root/.vnc/xstartup Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/macos-server:0.log
- Add X11 display to env:
root@macos-server:/home/ubuntu# export DISPLAY=:0 root@macos-server:/home/ubuntu# xhost + access control disabled, clients can connect from any host
- Enable libvirt and load the KVM kernel module:
root@macos-server:/home/ubuntu# sudo systemctl enable --now libvirtd root@macos-server:/home/ubuntu# sudo systemctl enable --now virtlogd root@macos-server:/home/ubuntu# echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs root@macos-server:/home/ubuntu# sudo modprobe kvm root@macos-server:/home/ubuntu# sudo usermod -aG docker "${USER}" root@macos-server:/home/ubuntu# sudo usermod -aG libvirt "${USER}" root@macos-server:/home/ubuntu# sudo usermod -aG kvm "${USER}"
Step 4. Run the macOS Image in Docker
- Run the following command to launch the macOS image in a Docker container:
root@macos-server:/home/ubuntu# 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 sickcodes/docker-osx:auto
Hereâs what youâll see:
Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. Host 127.0.0.1 User user Port 10022 IdentityFile ~/.ssh/id_docker_osx StrictHostKeyChecking no UserKnownHostsFile=/dev/null Default username: user Default password: alpine Change it immediately using the command: passwd Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. Last login: Sun Apr 9 17:37:35 2023
- Download and install a VNC client, such as TightVNC or RealVNC. A VNC client allows you to interact with the remote macOS.
- Run VNC client and start the new VNC Session with the following VNC Server:
VNC Server: <your_public_ip_address>:5900
For example:
VNC Server: 45.82.30.25:5900
Click OK and enter a username and password:
# username is user # password is alpine
Thatâs it! You have successfully installed macOS in Docker on a bare metal server with Ubuntu.
Conclusion
In this tutorial, we explained how to install macOS on bare metal with Ubuntu using Docker. Check out our other articles dedicated to setting up different types of software on Gcore Cloud instances: