If you are looking for a way to manage containers without a daemon, Podman APIs are the perfect solution for you. Podman APIs allow you to create, run, and manage containers using a simple RESTful interface. You can use Podman APIs with any programming language that supports HTTP requests, such as Python, Ruby, or Go. In this post, I will show you how to get started with Podman APIs in a few easy steps.
My project involved creating a software system that uses the Podman engine as the core component for running containerized workflows. The engine is fully abstracted away from the user by the backend service, which communicates with it through unix domain sockets and Podman APIs.
Introduction
Podman is a great alternative to Docker if you want to run containers and pods without a daemon. It offers a suite of tools, services and sdks that are compatible with the Docker CLI or the Kubernetes API. Podman is fast, secure and lightweight, and it supports Windows WSL v2. However, the documentation is not very clear or comprehensive and you might need some trial and error to figure things out. In this article, I will show you how to install podman on Ubuntu 22.04 image, using windows WSL v2. By the end of this tutorial, you will be able to use podman engine for your application development.
Step 1: podman setup and configuration
- Update the System: Update your system packages using the
sudo apt update
command. - Install Podman: Install Podman by running the command
sudo apt -y install podman
. You can verify the installation with the commandpodman -v
. - Initialize Podman: Initialize rootless Podman by executing
podman info
. - Configure Podman Registry: By default, the Podman registry is not configured to download and install container images from the web. You need to configure it first. You can look at the Podman registry configuration file with the command
sudo vi -R /etc/containers/registries.conf
. I prefer the simple drag and drop approach to messing up with the default configuration files; hence let’s add the following line to a new filedefault-podman.conf
and drop the file into the/etc/containers/registries.conf.d
folder.
|
|
|
|
Let’s check if the prefix based lookup works by executing podman search httpd
The results should be similar to the table below
INDEX | NAME | DESCRIPTION | STARS | OFFICIAL | AUTOMATED | FIELD7 | FIELD8 | FIELD9 | FIELD10 | FIELD11 | FIELD12 | FIELD13 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
fedoraproject.org | registry.fedoraproject.org/f29/httpd | 0 | ||||||||||
redhat.com | registry.access.redhat.com/rhscl/httpd-24-rhel7 | Apache | HTTP | 2.4 | Server | 0 | ||||||
redhat.com | registry.access.redhat.com/cloudforms46/cfme-openshift-app | Red | Hat® | CloudForms | Appliance | image | to | be | u… | 0 | ||
quay.io | quay.io/fedora/httpd-24 | 0 | ||||||||||
quay.io | quay.io/tike/openshift-sp-httpd | This | is | the | httpd | half | of | an | Openshift-ready… | 0 | ||
redhat.io | registry.redhat.io/rhscl/httpd-24-rhel7 | Apache | HTTP | 2.4 | Server | 0 | ||||||
redhat.io | registry.redhat.io/rhel8/httpd-24 | Apache | HTTP | Server | 2.4 | available | as | containe… | 0 |
Step 2: podman API service configuration
To use Podman, you need to start the podman system service first. This service listens for API calls from Podman clients and runs them on Linux systems. You can use systemd
to run this service automatically.
- Let’s check the id of my current user
|
|
- Start the service as the user service
systemctl --user start podman.socket
systemctl --user status
check that the service is running as expected
The results should look like the following: you can see the podman is listening to the socket of the user with the id 1000
|
|
- Configure the systemd socket to be automatically started after reboots, and run as the specified user.
|
|
- Check that unix domain socket is exposed to this user
|
|
- the last step would be to try to connect the socket
|
|
at this point you can start hacking
Effective development using Podman APIs
Podman system service supports two kinds of REST APIs: a compatibility layer that works with Docker v1.40 API, and a Libpod layer that is specific to Podman. You can find the documentation for the Libpod API at this reference. The APIs have different versions, but the server does not check the version of the requests.
One of the challenges of working with the Podman API is that the documentation does not cover all the details and features of the API. You may need to try different approaches and parameters to get the functionality you want.
A useful tip is to look at the swagger yaml file that defines the API schema. However, be aware that some of the models are not well-defined or have a generic type of Any. This means that you may encounter unexpected errors or behaviors when using the API.
Here is a tip that may help you when you are testing:
- Download the swagger document and import it into a tool like Postman. You can find it on the same page as this reference
- Use the amazing hacking tool socat to forward the unix domain socket to the host TCP port.
|
|
and now you can work productively.