Podman - Machine (Podman on macOS)

Podman Oct 19, 2021

You want to use Podman, but you are on a Mac? Podman Machine may be something you are interested in. It is the built-in way to run Podman in a virtual machine on your Workstation.

Let's dig into it.

Podman

As you may be aware, Podman is a drop-in-replacement for Docker and can handle containers daemonless and even rootless on Linux. You can create, run, build and interact with containers as described in my blog articles about Podman. If you are completely new to Podman, please check out "Podman - Getting Started" beforehand.

But, what about Mac users? Since Containers are heavily bound to Linux (cgroups, kernel namespaces, IPC), there is no way to have OCI Containers natively on Mac, for now. But this does not mean, that you cannot develop Containers on your Mac. Podman provides some tooling to help you.

Podman Machine

Podman Machine is a set of tools to create a Linux VM on your Mac and have Podman in this machine. You can use the Podman command line tool as if you are running Podman natively. With a little wizardry from the Podman developers, it feels like you are running Podman on your Mac.

It is very similar to Docker Desktop, but free for everybody.

This also works on Linux systems, that either do not support Podman in a current version or, if you just want to sandbox your development containers in a VM. The only thing you need is Podman and QEMU.

Before you ask, this should be supported on M1 (Apple Silicon), too. But I haven't tested it on my own.

Update via Twitter: The M1 support seems to work properly.

Thanks a lot for this :)

Hint
The guide is tested on macOS Big Sur and Fedora 34 with Podman 3.4.0.

Installation

You may wonder: "How do I install this stuff?" It is quite easy, if you already have Homebrew installed. If not, please check out the documentation. It is a package manager for macOS and you can install all kinds of stuff like Ansible, Python or Podman with some simple commands.

Done? Cool :) Let's continue.

First step: You will need to install the packages via Homebrew.

# Install Podman and QEMU
$ brew install qemu podman

Second step: You can continue with the next section and start using Podman. ;)

First Steps

You finally got it here. ^^ Fun aside, let's see how you can start using Podman on your Mac.

Initialize a new machine

As stated above, Podman will need a Virtual Machine with Podman inside. Therefore, you also needed to install QEMU in the installation section. Let's create one.

# Initialize new Podman machine
$ podman machine init
Downloading VM image: fedora-coreos-34....

The command will download a Fedora CoreOS image. You don't need to repeat this step for every new machine.

Start a new machine

Starting the new Podman machine will spin up a Virtual Machine (based on Fedora CoreOS) and will prepare your Podman to interact with the machine.

# Start a new Podman machine
$ podman machine start

This will also prepare some network configuration, so this machine can communicate to the internet and download container images or being accessed, if you want so.

Containers

Finally, we can start running containers. Interacting with containers is basically the same as discussed in my other guides and Podman articles. In the below code, you can find some simple commands to get you started.

# Download an image
$ podman image pull docker.io/library/httpd

# Start a container from the image
$ podman container run -dt docker.io/library/httpd

# Check running containers
$ podman container ls

# Stop a running container
$ podman container stop CONTAINER_ID

In fact, you can play with basically all commands, that also work in Linux.

Cleanup

If you are done with your work, you can also stop or delete the VM, so your system stays clean.

# List machines
$ podman machine list

# Stop machine
$ podman machine stop

# Remove machine
$ podman machine rm

Stopping the VM/machine will just halt it, and you can start it again at any point in the future again. Deleting the machine will remove the VM, and it's content.

More machine commands

There are also some commands, that may be helpful, if you need to debug something or just want to interact with the VM a bit more.

# SSH into machine
$ podman machine ssh

# Start a machine with fixed CPU/Memory resources
$ podman machine start --cpus=2 --memory=2048

# Start a machine with a fixed name (this way you can have multiple machines)
$ podman machine start MACHINE_NAME

There are more examples in the Podman machine documentation that may be interesting for you.

You can find a couple of articles about Podman machine at the web. Since the feature is quite new and also rebranded from boot2podman, some articles, you can find, may be a bit outdated, but still helpful.

Podman
How Podman runs on Macs and other container FAQs
Clearing up confusion about Podman’s machine architecture and other frequently asked questions.
Run a Linux virtual machine in Podman
Fedora CoreOS is an automatically updating, minimal rpm-ostree-based operating system for running containerized workloads securely and at scale. [OS_EMBEDDED_MENU_RIGHT:]Podman “is a tool for managing containers and images, volumes mounted into those containers, and pods made from groups of containe…
Running Podman machine on macOS
I use podman for containers with the help of Fedora machine. But on my macOS, I have to rely on Fedora Machine installed on virtualbox with podman. I was looking for a native solution which will…

Conclusion

Building OCI containers still requires a Linux machine, but Podman makes it very easy to and friction-less to get such a machine and don't care about it.

At least from a development perspective, this allows you to spin up containers, build images and push them wherever you need it. Running Podman containers for production workload on macOS is still not recommended, but for Development - Go for it!

Please let me know if you are a Mac user, so I may provide additional Mac related articles.

Tags

Daniel Schier

Just a guy doing stuff. Mostly #FLOSS like #Linux, #Ansible, #Podman, #K8s, #Python, #Nextcloud or whatever comes next.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.