If you are trying to run Mac OS as the base system in a Docker container, unfortunately there is no way to do it. Docker container need to use the host machine's Linux Kernel, since Mac OS family is Unix-based operating system, currently Docker cannot simulate a Mac OS in Docker container. Here is a link to explain how container works. MacOS and Windows have traditionally not supported the Linux-based container technology that powers Docker, but the latest release of Docker for Mac and Windows now makes it easier to get started creating and running containers in those environments with less overhead. Let’s put a simple Node.js application in a Docker container as an example.
Several months ago, I came back to my desk after lunch and to my chagrin, my macOS was making a long constant blowing sound—the fan was on high speed. Now, mind you, I have a fairly new and beefy Mac. 2.4 GHz, 8-core, 64GB running Big Sur, 11.2.1. So what in the world could be triggering my fan to such a high level? I discovered that the culprit was Docker. And the only way to rid myself of the noise was a Docker restart.
At that moment, I added a task to my To-Do list: Replace Docker with Podman. However, early attempts and initial research proved difficult simply because I wanted it to be just as easy to start Podman on my Mac as is the Docker client. I use Alfred (Spotlight replacement) and launch most things with a quick cmd+space. So, if I couldn’t do the same with Podman, I was going to have to take a hard pass on the replacement. And, unfortunately, there isn’t a one-click, easy Podman macOS install, so I had to stitch a couple of few items together to get that quick launch. To help you have a better experience, I've documented the process here.
[ Readers also liked: From Docker Compose to Kubernetes with Podman ]
A couple of months ago, I was able to get Podman running on my Mac via
podman-machine, but I ran out of time and motivation to convert it into something easy to launch. Fast forward a couple of months,
podman-machine is now deprecated in lieu of Vagrant. I found a couple of good articles, like Brent and Ashley’s post on
podman remote, which provided most of my answer and helped me figure out how to deal with some fun podman.sock errors. However, I couldn’t find my holy grail. I mean, I’m a lazy dude. My frustration level is measured by the amount of typing or clicks it takes me to do something. And if it’s more than a couple of clicks, I’ll need to go eat more pizza to calm me down. So, here it is in three main parts: The pre-requisites, creating a script, and then creating the macOS app.
1. You’ll need the latest version of VirtualBox
2. Install Vagrant
$ brew install podman
4. Create a directory to store the Vagrantfile, such as
/Users/[username]/tools/podman (you’ll need to modify scripts below to use this directory)
5. Create the following Vagrantfile in your new directory. I’m using Andres’ Vagrant file, but I found others as well.
6. Add the following lines to your
~/.zshrc file to create global environment variables for the Podman host and SSH key. This step allows you to make a successful connection in any terminal window. Note the second variable contains a directory that needs to be changed to reflect your setup.
7. Create the following bash shell script. Note the change required to reflect your setup. I called my script pman.
At this point, you can open a terminal and type
$ pman up to start Podman. But, I told you I was lazy, right? That’s way too many clicks and keypresses for my taste, so I made this a macOS app.
1. Open up Automator on your Mac, and choose Application as your document.
2. Drag and drop the Run Shell Script item into the workflow, and type the following script:
Note: The example path
~/Dev/bin/pman will need to be updated to where you saved and named the bash script above.
3. Save the Application. It should save directly into the Mac Applications folder. I called my Podman application Seals because of the Podman logo.
4. As an added bonus, I found the Podman logo and created a 128x128 PNG image with GIMP to use as the application icon:
[ Get this free ebook: Managing your Kubernetes clusters for dummies. ]
There you have it. Now you can use Spotlight or Alfred to run Podman. It’s just a cmd+space and a couple of letters away.