This directory contains a sample application to run Podman operations in external applications via a set of Go bindings which are later exported as C shared library. Due to a limitation of such export, wrappers are needed around original Go bindings.
There's a single Go file, which uses the Podman Go bindings to provide interface to execute following steps from C application:
- Pull Image
- List Images
- Start Container
- List Containers
- Inspect Container
- Stop Container
There is example main.c which demonstrates the usage of above operations.
-
Clone the repo and enter to the directory.
-
Ensure podman.socket is activated
$ systemctl --user start podman.socket
- Start service (here using podman command)
$ podman system service -t 0
- Build go wrapper library (this step will generate C header file as well)
$ go build -buildmode=c-shared -o libpodc.so libpodc.go
- Build example C application
$ gcc -O2 -L. -Wl,-rpath=. -Wall -o main main.c -lpodc
- Run it
$ ./main
Trying to pull registry.fedoraproject.org/fedora-minimal:latest...
Getting image source signatures
Copying blob sha256:2fa61fedb54d576e17d9129a27fbd3c1ff8503b1e0c45622ba8de6a51fb6a9ef
Copying config sha256:fa011f8784baff6b77fc56152b5024c368809c0f4c6b1279dbd9b173f534028a
Writing manifest to image destination
Storing signatures
Listing images...
[k8s.gcr.io/pause:3.2 docker.io/jess/chromium:latest registry.fedoraproject.org/fedora:latest docker.io/library/busybox:latest registry.fedoraproject.org/fedora-minimal:latest]
INFO[0002] Going to start container "a6171bb2da55377d58e0bd05e1469a9a1f4ab83e406050c0521e23f40c5a8518"
Status of the container with imgName: registry.fedoraproject.org/fedora-minimal:latest is: running
- Go wrapper library is based on demo application: https://github.com/containers/Demos/tree/master/podman_go_bindings
- For go troubleshooting refer to: https://podman.io/blogs/2020/08/10/podman-go-bindings.html