Comment by paxys

7 days ago

It's impossible to have "native" support for Linux containers on macOS, since the technology inherently relies on Linux kernel features. So I'm guessing this is Apple rolling out their own Linux virtualization layer (same as WSL). Probably still an improvement over the current mess, but if they just support LXC and not Docker then most devs will still need to install Docker Desktop like they do today.

Apple has had a native hypervisor for some time now. This is probably a baked in clone of something like https://mac.getutm.app/ which provides the stuff on top of the hypervisor.

  • In case you're wondering, the Hypervisor.framework C API is really neat and straightforward:

    1. Creating and configuring a virtual machine:

        hv_vm_create(HV_VM_DEFAULT);
    

    2. Allocating guest memory:

        void* memory = mmap(...);
        hv_vm_map(memory, guest_physical_address, size, HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
    

    3. Creating virtual CPUs:

        hv_vcpu_create(&vcpu, HV_VCPU_DEFAULT);
    

    4. Setting registers:

        hv_vcpu_write_register(vcpu, HV_X86_RIP, 0x1000); // Set instruction pointer
        hv_vcpu_write_register(vcpu, HV_X86_RSP, 0x8000); // Stack pointer
    

    5. Running guest code:

        hv_vcpu_run(vcpu);
    

    6. Handling VM exits:

        hv_vcpu_exit_reason_t reason;
        hv_vcpu_read_register(vcpu, HV_X86_EXIT_REASON, &reason);

  • One of the reasons OrbStack is so great is because they implement their own hypervisor: https://orbstack.dev/

    Apple’s stack gives you low-level access to ARM virtualization, and from there Apple has high-level convenience frameworks on top. OrbStack implements all of the high-level code themselves.

  • Using a hypervisor means just running a Linux VM, like WSL2 does on Windows. There is nothing native about it.

    Native Linux (and Docker) support would be something like WSL1, where Windows kernel implemented Linux syscalls.

    • Hyper-V is a type 1 hypervisor, so Linux and Windows are both running as virtual machines but they have direct access to hardware resources.

      It's possible that Apple has implemented a similar hypervisor here.

    • Surely if Windows kernel can be taught to respond to those syscalls, XNU can be taught it even easier. But, AIUI the Windows kernel already had a concept of "personalities" from back when they were trying to integrate OS/2 so that zero-to-one for XNU could be a huge lift, not the syscalls part specifically

      9 replies →

    • > The Containerization framework enables developers to create, download, or run Linux container images directly on Mac. It's built on an open-source framework optimized for Apple Silicon and provides secure isolation between container images

      That's their phrasing, which suggests to me that it's just a virtualization system. Linux container images generally contain the kernel.

      5 replies →

The screenshot in TFA pretty clearly shows docker-like workflows pulling images, showing tags and digests and running what looks to be the official Docker library version of Postgres.

  • Every container system is "docker-like". Some (like Podman) even have a drop-in replacement for the Docker CLI. Ultimately there are always subtle differences which make swapping between Docker <> Podman <> LXC or whatever else impossible without introducing messy bugs in your workflow, so you need to pick one and stick to it.

  • Yeah, from a quick glance the options are 1:1 mapped so an

      alias docker='container'
    

    Should work, at least for basic and common operations

What about macOS being derived from BSD? Isn’t that where containers came from: BSD jails?

I know the container ecosystem largely targets Linux just curious what people’s thoughts are on that.

WSL throughput is not enough for file intensive operations. It is much easier and straightforward to just delete windows and use Linux.

  • Using the Linux filesystem has almost no performance penalty under WSL2 since it is a VM. Docker Desktop automatically mounts the correct filesystem. Crossing the OS boundary for Windows files has some overhead of course but that's not the usecase WSL2 is optimized for.

    With WSL2 you get the best of both worlds. A system with perfect driver and application support and a Linux-native environment. Hybrid GPUs, webcams, lap sensors etc. all work without any configuration effort. You get good battery life. You can run Autodesk or Photoshop but at the same time you can run Linux apps with almost no performance loss.

If they implemented the Linux syscall interface in their kernel they absolutely could.

  • Aren't the syscalls a constant moving target? Didn't even Microsoft fail at keeping up with them in WSL?

    • Linux is exceptional in that it has stable syscall numbers and guarantees stability. This is largely why statically linked binaries (and containers) "just work" on Linux, meanwhile Windows and Mac OS inevitably break things with an OS update.

      Microsoft frequently tweaks syscall numbers, and they make it clear that developers must access functions through e.g. NTDLL. Mac OS at least has public source files used to generate syscall.h, but they do break things, and there was a recent incident where Go programs all broke after a major OS update. Now Go uses libSystem (and dynamic linking)[2].

      [1] https://j00ru.vexillium.org/syscalls/nt/64/

      [2] https://go.dev/doc/go1.11#runtime

      1 reply →

    • Not Linux syscalls, they are a stable interface as far as the Linux kernel is concerned.

    • They're not really a moving target (since some distros ship ancient kernels, most components will handle lack of new syscalls gracefully), but the surface is still pretty big. A single ioctl() or write() syscall could do a billion different things and a lot of software depends on small bits of this functionality, meaning you gotta implement 99% of it to get everything working.

WSL doesn't have a virtualization layer, WSL1 did have but it wasn't a feasible approach so WSL2 is basically running VMs with the Hyper-V hypervisor.

Apple looks like it's skipped the failed WSL1 and gone straight for the more successful WSL2 approach.