Native MacOS Docker Containers are Now Possible
Have you ever wished you could run native macOS Docker containers on macOS? Well, now you can, thanks to a great free project called macOS Containers.
If you’re in the developer world at nearly any level, you likely have experience with Docker containers, which are wildly popular because of their utility. Offering a lightweight and efficient way to package and distribute applications and dependencies across varying environments, Docker containers are self-contained, and able to help with rapid deployment, management, and scalability when developing or testing applications, software, systems, and much more. Up until now, containers were not natively supported by MacOS, but thanks to macOS Containers, that has changed.
Native macOS Containers are in early development with this project, but with them you can run macOS inside macOS, build images with Docker, and distribute them, sounds great right?
There are a few caveats that you’ll need to be comfortable with; first, the project is ‘very alpha’ according to the developers and so it’s obviously use at your own risk, and second, you need to disable SIP on the Mac, and third you’ll need to install Homebrew on Sonoma, Ventura,, Monterey, or Catalina (and yes that means those are also the only supported macOS host operating systems). If you’re comfortable with all of that, check out the project on GitHub, and fire up Homebrew to install macOS Containers and get going.
The project home page is at https://macoscontainers.org and the Github page is here.
Jump into the Terminal to get started.
Assuming you have Homebrew already installed, you’ll need to install MacFuse:
brew install --cask macfuse
Next, you need to install the macOS Container Docker build:
brew install docker docker-buildx macOScontainers/formula/dockerd
After that has finished, start containerd:
sudo brew services start containerd
Then start dockerd:
sudo brew services start dockerd
Next, you setup BuildKit by first creating a directory for plugins;
mkdir -p ~/.docker/cli-plugins
And then linking buildkit to docker:
ln -sfn /opt/homebrew/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx
You’ll now want to authenticate to GitHub Container registry:
echo [YOUR_ACCESS_TOKEN] | docker login ghcr.io -u [GITHUB_USERNAME] --password-stdin
And finally, it’s time to run your first native macOS container:
docker run --rm -it ghcr.io/macoscontainers/macos-jail/ventura:latest echo "Hello from macOS container"
These instructions are from the GitHub page here, which you can refer to if you want more information.
There’s also a fascinating discussion of this project going on over at HackerNews on ycombinator that is worth checking out if you’re curious about the project from a developer perspective.
As you may know, Docker containers are so popular and useful because they offer a lightweight and efficient way to offer consistent packages that can be used to distribute and run applications and their dependencies in different environments. By including an application and dependencies in a self-contained container, it makes it easy for developers to ensure that their software runs consistently on whatever other systems they are deployed to, which can help to improve development times, deployment, scaling, management, and so much more.
In some ways Docker images and containers are kind of like virtual machines, but they’re aimed at developers and software projects. If you’re more interested in virtualizing an operating system for a tinkerers perspective or just to goof around, rather than a developer perspective, check out our posts on virtual machines here.