Can Mac OS X be run inside Docker?

Can Mac OS X be run inside Docker? If so, any suggestion as to how?

And would it be running headless, or there would be a possibility to connect to the GUI remotely?

Docker provides methods for managing OS-level containers and is built on top of Linux's native features for OS-level containerization. All containers running on a system share the same kernel; Mac OS X does not use the Linux kernel, but rather a mach kernel, so it cannot be run inside a Docker container at this time.

You can run Docker on your Mac using a virtual machine, but containers running on that instance would need to run Linux.

Now that Docker uses libcontainer rather than LXC as its basis, it is possible that porting of libcontainer in the future could one day allow for running Windows and Mac OS Docker containers on those systems respectively, but it would depend on appropriate OS features being available to allow for containerization.

Running an OSX VM in a Docker container is possible. Take a look at https://github.com/Cleafy/sxkdvm for example.

If you want to run macOS directly inside Docker, the answer is no, see @phoebus's answer.

If you really need it it, see @Andrea Brancaleon's answer which suggests to install macOS inside VM inside Docker.

But if you're wondering if the solution above is possible according to macOS' licence, than the answer is again no*.

Quoting software license agreement for macOS Catalina, section 2, point B:

[...] you are granted a limited, non-transferable, non-exclusive license: [...]
(iii) to install, use and run up to two (2) additional copies or instances of the Apple Software
within virtual operating system environments on each Mac Computer you own or control that is
already running the Apple Software, for purposes of: (a) software development; (b) testing during
software development; (c) using macOS Server; or (d) personal, non-commercial use.

It's same for older macOS versions.


* unless you're going to run macOS inside a virtual machine inside a Linux Docker container inside a Linux virtual machine on macOS host system on Mac hardware