How to use podman - 10 common examples

To help you get started, we’ve selected a few podman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github containers / python-podman / test / test_images.py View on Github external
def loadCache(self):
        with podman.Client(self.host) as pclient:
            self.images = list(pclient.images.list())

        self.alpine_image = next(
            iter(
                [
                    i
                    for i in self.images
                    if "docker.io/library/alpine:latest" in i["repoTags"]
                ]
                or []
            ),
            None,
        )

        return self.images
github containers / python-podman / test / test_pods_no_ctnrs.py View on Github external
def setUp(self):
        self.tmpdir = os.environ['TMPDIR']
        self.host = os.environ['PODMAN_HOST']

        self.pclient = podman.Client(self.host)
github containers / python-podman / test / test_images.py View on Github external
def setUp(self):
        self.tmpdir = os.environ["TMPDIR"]
        self.host = os.environ["PODMAN_HOST"]

        self.pclient = podman.Client(self.host)
        self.images = self.loadCache()
github containers / python-podman / test / test_pods_no_ctnrs.py View on Github external
def test_045_raises_no_ctnrs(self):
        global ident, pod

        with self.assertRaises(podman.NoContainersInPod):
            pod.start()

        with self.assertRaises(podman.NoContainersInPod):
            pod.restart()

        with self.assertRaises(podman.NoContainerRunning):
            next(pod.stats())

        with self.assertRaises(podman.ErrorOccurred):
            pod.top()
github containers / python-podman / test / test_containers.py View on Github external
def test_get(self):
        actual = self.pclient.containers.get(self.alpine_ctnr.id)
        for k in ['id', 'status', 'ports']:
            self.assertEqual(actual[k], self.alpine_ctnr[k])

        with self.assertRaises(podman.ContainerNotFound):
            self.pclient.containers.get("bozo")
github containers / python-podman / examples / eg_latest_containers.py View on Github external
#!/usr/bin/env python3
"""Example: Show all containers created since midnight."""

from datetime import datetime, time, timezone

import podman

print('{}\n'.format(__doc__))


midnight = datetime.combine(datetime.today(), time.min, tzinfo=timezone.utc)

with podman.Client() as client:
    for c in client.containers.list():
        created_at = podman.datetime_parse(c.createdat)

        if created_at > midnight:
            print('{}: image: {} createdAt: {}'.format(
                c.id[:12], c.image[:32], podman.datetime_format(created_at)))
github containers / python-podman / test / test_images.py View on Github external
with open(path, "w") as stream:
            stream.write("FROM alpine")

        builder = self.pclient.images.build(
            containerfiles=[path], tags=["alpine-unittest"]
        )
        self.assertIsNotNone(builder)

        for line, img in builder():
            # drain the generator...
            continue

        self.assertIsNotNone(img)
        self.assertIn("localhost/alpine-unittest:latest", img.repoTags)
        self.assertLess(
            podman.datetime_parse(img.created), datetime.now(timezone.utc)
        )
github containers / python-podman / examples / eg_latest_containers.py View on Github external
from datetime import datetime, time, timezone

import podman

print('{}\n'.format(__doc__))


midnight = datetime.combine(datetime.today(), time.min, tzinfo=timezone.utc)

with podman.Client() as client:
    for c in client.containers.list():
        created_at = podman.datetime_parse(c.createdat)

        if created_at > midnight:
            print('{}: image: {} createdAt: {}'.format(
                c.id[:12], c.image[:32], podman.datetime_format(created_at)))
github containers / python-podman / test / test_client.py View on Github external
def test_remote(self, mock_ping):
        p = Client(
            uri='unix:/run/podman',
            interface='io.podman',
            remote_uri='ssh://user@hostname/run/podman/podman',
            identity_file='~/.ssh/id_rsa')

        self.assertIsInstance(p._client, BaseClient)
        mock_ping.assert_called_once_with()
github containers / python-podman / test / test_client.py View on Github external
def test_local(self, mock_ping):
        p = Client(
            uri='unix:/run/podman',
            interface='io.podman',
        )

        self.assertIsInstance(p._client, LocalClient)
        self.assertIsInstance(p._client, BaseClient)

        mock_ping.assert_called_once_with()