Skip to content

Podman pods

Don't use the constructor directly. Instead use

from python_on_whales import DockerClient

podman = DockerClient(client_call=["podman"])

my_pod = podman.pod.inspect("my-pod-name")

# or

my_pod = podman.pod.create("my-pod-name")

For type hints, use this

from python_on_whales import Pod

def print_container_names(pod: Pod):
    print([ctr.name for ctr in pod.containers])

Attributes

The attributes are the same that you get with the command line: podman pod inspect ...

If you want to know the exact structure, you can go to the podman pod inspect reference page

An example is worth many lines of descriptions.

In [1]: from python_on_whales import DockerClient

In [2]: podman = DockerClient(client_call=["podman"])

In [3]: pod = podman.pod.create("my-pod")

In [4]: def super_print(obj):
   ...:     print(f"type={type(obj)}, value={obj}")
   ...:

In [5]: super_print(pod.id)
type = <class 'str'>, value = e307d4b1219b935699befc417a2005fef60fd9133b5eb928d4d3314a55e76fe7

In [6]: super_print(pod.name)
type = <class 'str'>, value = my-pod

In [7]: super_print(pod.created)
type = <class 'datetime.datetime'>, value = 2024-11-20 11:35:39.966456+00:00

In [8]: super_print(pod.state)
type = <class 'str'>, value = Created

In [9]: super_print(pod.num_containers)
type = <class 'int'>, value = 1

In [10]: super_print(pod.infra_container_id)
type = <class 'str'>, value = 1cf2cad55d42716b4bf7832480ea09c98c7307aee90bb7c4f0ec384af01bce2f

In [11]: super_print(pod.shared_namespaces)
type = <class 'list'>, value = ['ipc', 'net', 'uts']

In [12]: super_print(pod.hostname)
type = <class 'str'>, value = 

In [13]: super_print(pod.exit_policy)
type = <class 'NoneType'>, value = None

Methods

Pod

exists

exists()

Returns True if the pod exists and False if not.

See the podman.pod.exists command for information about the arguments.

kill

kill(*, signal=None)

Kill this pod

See the podman.pod.kill command for information about the arguments.

logs

logs(container=None, *, names=False, since=None, tail=None, timestamps=False, until=None, follow=False, stream=False)

Returns the logs of the pod containers

See the podman.pod.logs command for information about the arguments.

pause

pause()

Pause this pod.

See the podman.pod.pause command for information about the arguments.

remove

remove(*, force=False, time=None)

Remove this pod.

See the podman.pod.remove command for information about the arguments.

restart

restart()

Restart this pod.

See the podman.pod.restart command for information about the arguments.

start

start()

Starts this pod.

See the podman.pod.start command for information about the arguments.

stop

stop(*, time=None)

Stops this pod.

See the podman.pod.stop command for information about the arguments.

unpause

unpause()

Unpause the pod

See the podman.pod.unpause command for information about the arguments.