appleInstall a macOS VM in a WSL-based Docker

Reference: https://www.bilibili.com/video/BV1j2421o77K/

This is an ultimate matryoshka Mac system, which I installed into a Linux subsystem running on Windows inside a Docker container. It's a combination of three major operating systems all at once. We can use this system to try out some Mac-specific software, develop cross-platform software, test compatibility, and more.

In this page, let's take a look at how to set up this interesting system. For this project, I'm using Docker OSXarrow-up-right, whichc cows you to quickly start a MacOS environment using Docker. However, this project has fairly high hardware requirements, and a Linux mini-computer's performance may not be sufficient. So this time, I'm going to run Docker on my Windows computer.

First, initial setup for Docker-OSX to run on Windows

Go to C:/Users/<Your_Name>/.wslconfig and add nestedVirtualization=true to the end of the file (If the file doesn't exist, create it). For more information about the .wslconfig file check this linkarrow-up-right. Verify that you have selected "Show Hidden Files" and "Show File Extensions" in File Explorer options. The result should be like this:

This step is to allow nesting of virtual machines.

⚠️If you are running your WSL, don't forget to run wsl --shutdown to activate the above config.

Second, install a Docker desktop

🔗Downloading links:

Third, modify configuration

Modification

Insure that the options, framed in the figures below, are selected.

select "Use the WSL 2 based engine"
select "Enable integration with my default WSL distro" and your default WSL, then check "Apply & restart"

Verification

Enter docker ps in your WSL to check whether you can use docker in your WSL.

You success if you get the following return:

check if KVM is enabled by using the kvm-ok command. The output should look like this:

Fourth, install mac OS in docker

Choose the corresponding image of mac OS from here: https://github.com/sickcodes/Docker-OSX?tab=readme-ov-file#technical-detailsarrow-up-right

For an example, I choose Ventura (2.36GB).

  • Code for 🇬🇧:

  • Code for 🇨🇳:

ERROR: wsl: 检测到 localhost 代理配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost 代理

SOLUTION: [Referencearrow-up-right]

ERROR: curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 16 ms: Couldn't connect to server

SOLUTION1: add the following codes into the loacal host file (sudo vim /etc/hosts)[Referencearrow-up-right]:

🌟SOLUTION2: set proxy for wsl

⚠️NOTE: <your_proxy_server> can be accessed after Enable LAN connection on your proxy client (vEthernet (WSL (Hyper-V firewall))).

Last updated