Podman as an Alternative to Docker in MacOS
In the era of software development in Container Technology using Kubernetes as container management with Kubernetes distributions like OpenShift, Rancher and Tanzu, the most common tool available is Docker. It is available in most platforms from personal computers (PC) to mainframe computers (e.g. IBM LinuxONE) and popular operating systems like Windows, MacOS and Linux.
Developers normally like to find alternate tools and this is where Podman comes in handy. Docker has a lot of features which Podman may not directly replace, however, for software development of container based applications in you local computer. Podman can be used to build, run containers images and upload to public container registry like Docker Hub or quay.io.
I wanted to explore Podman and in my journey of searching how to install Podman in my system, I came out with the following which worked out for me.
These are the summary of the steps to install and test Podman in MacOS:
- Install VirtualBox and Podman
- Install Vagrant and create VM
- Install and setup Podman in the Virtual Machine
- Connect podman client and Test Podman
Now, moving on to the detailed steps:
Step 1: Install VirtualBox and Podman
Most of the container images are based on Linux OS and since MacOS has different Kernel from Linux OS, we have to create a Virtual Machine to host the Linux OS which in turn will run applications in the container.
We will be using VirtualBox to create our VM in MacOS. Download and install VirtualBox.
For Podman on MacOS you can use brew to install or go to Podman website to get the instructions and download the latest release.
brew cask install podman
Step 2: Install Vagrant and create VM
We will be using Vagrant to mange our VM in VirtualBox. Download and Install Vagrant. Please refer to Vagrant website to get detailed instruction on how to create the configuration file Vagrantfile.
After installing Vagrant, to create the VM, we need to create a configuration file called Vagrantfile. Create a directory where the Vagrantfile and VMs will reside. For me I created a directory ~/Tools/podman where I saved the Vagrantfile.
Create a Vagrantfile using your favourite editor. For heavy container loads adjust the v.memory and v.cpu values accordingly, in a similar way adjusting the preferences in Docker.
Vagrant.configure("2") do |config| config.vm.box = "generic/fedora33" config.vm.hostname = "podman-server" config.vm.provider "virtualbox" do |v| v.memory = 1024 v.cpus = 1 endend
This is a sample directory listing of the file.
-rw-r--r-- 1 user staff 750 Apr 15 10:07 Vagrantfile
To create the VM from the Vagrantfile, run the following command in the directory where the Vagrantfile is located.
vagrant up
after typing the above command, this is a sample reduced output:
❯ vagrant upBringing machine 'default' up with 'virtualbox' provider...==> default: Importing base box 'generic/fedora33'...==> default: Matching MAC address for NAT networking...==> default: Checking if box 'generic/fedora33' version '3.2.16' is up to date....
.
.default: Key inserted! Disconnecting and reconnecting using new SSH key...==> default: Machine booted and ready!==> default: Checking for guest additions in VM...==> default: Setting hostname...
After successful creation of the VM, you can verify in VirtualBox application
Tip:
To access your VM in any directory, you can use the command vagrant global-status to get the VM id. Running the command will display the following:
id name provider state directory
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
eee4ea0 default virtualbox running /Users/<user>/Tools/podman
To use the extended command vagrant <command> <VM id>
vagrant up eee4ea0
Take note that the global command can only be used after the VM has been created.
Step 3: Install and setup Podman in the Virtual Machine
Once the VM is running, we can now ssh to the VM to install and setup Podman in the VM.
vagrant ssh
Install Pod man and add group
sudo yum install -y podman
sudo groupadd -f -r podman
Create override.conf
sudo systemctl edit podman.socket
In the VI editor copy and paste the following. For VI press i for insert and paste the following. Once done press ESC to exit the insert mode then press colon : for command and press wq to save and exit.
[Socket]
SocketMode=0660
SocketUser=root
SocketGroup=podman
Restart the daemon with
sudo systemctl daemon-reload
Create podman.conf in /etc/tmpfiles.d
sudo vi /etc/tmpfiles.d/podman.conf
then copy and base the following:
d /run/podman 0770 root podman
Enable, start podman.socket and add user sudo user vagrant
sudo systemctl enable podman.socket
sudo systemctl start podman.socket
sudo usermod -aG podman vagrant
To exit from the VM
exit
Step 4: Connect podman client and Test Podman
Connect the podman client to the VM, add the following environment variables to your ~/.zshrc.
export CONTAINER_HOST=ssh://vagrant@127.0.0.1:2222/run/podman/podman.sock
for SSH key, Replace <username> with the corresponding username and check the correct directory.
export CONTAINER_SSHKEY=/Users/<username>/Tools/podman/.vagrant/machines/default/virtualbox/private_key
To test run the common Docker hello-world
podman run hello-world
Should return
Resolved "hello-world" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)Trying to pull docker.io/library/hello-world:latest...Getting image source signaturesCopying blob sha256:b8dfde127a2919ff59ad3fd4a0776de178a555a76fff77a506e128aea3ed41e3Copying config sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726Writing manifest to image destinationStoring signaturesHello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/For more examples and ideas, visit:https://docs.docker.com/get-started/
Congratulations! You have successfully run your first container using Podman and use Podman instead of Docker.
Thanks to the following:
and