Install macOS on Gcore Bare Metal with Ubuntu Using Docker

Install macOS on Gcore Bare Metal with Ubuntu Using Docker

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:

  1. Log in to your Gcore Cloud account. If you don’t have it yet, sign up.
  2. Go to Cloud and select Projects.
  3. 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.
  4. In your project, select Baremetal and click Create Baremetal Server.
Screenshot of the Baremetal section
Figure 1: Click “Create Baremetal Server”
  1. 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.)
  2. 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.”
Screenshot of the created server
Figure 2: The bare metal server’s status is “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.

  1. 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
  1. 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
  1. 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
  1. 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:
  1. 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
  1. 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
  1. 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

  1. 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
  1. Download and install a VNC client, such as TightVNC or RealVNC. A VNC client allows you to interact with the remote macOS.
  1. 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
Screenshot of the VNC client
Figure 3: Running the VNC client

Click OK and enter a username and password:

# username is user
# password is alpine
Screenshot of the macOS desktop
Figure 4: macOS successfully installed

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:

Install macOS on Gcore Bare Metal with Ubuntu Using Docker

Subscribe
to our newsletter

Get the latest industry trends, exclusive insights, and Gcore
updates delivered straight to your inbox.