Interactive Use of Podman

In contrast to Docker, podman(1) is designed to work well as a user utility.


Ephemeral Containers

To run an ephemeral container interactively, try:

podman run --interactive --tty --rm alpine:latest

The container will be cleaned up once it stops running.


Running Containers

To open a shell with a running container, try:

podman exec --interactive --tty my-container /bin/sh

A different shell binary can be used, but many images are purposefully slimmed down and will not have anything other than sh(1) installed.


Copying Files

It is possible to pass data in and out of containers with pipes.

Some documents recommend using something like the below for copying files from a container.

podman run --rm httpd:2.4 cat /usr/local/apache2/conf/httpd.conf > my-httpd.conf

Instead, consider using podman cp.

podman cp my-container:/absolute/path/to/container/file relative/path/to/destination/file
podman cp relative/path/to/host/file my-container:/absolute/path/to/destination/file

podman cp generally behaves like cp would, but it should be noted that it internally uses a tar(1) stream.

podman cp my-container:/absolute/path/to/container/file relative/path/to/destination/directory/
podman cp my-container:/absolute/path/to/container/directory/ relative/path/to/destination/directory/
podman cp my-container:/absolute/path/to/container/file - | tar x --to-stdout | grep "ERROR"

Note how - is used to indicate that STDOUT is the destination.

The former strategy can still be useful in certain circumstances:

podman exec my-container tar -C /path/to/container/data/directory -czf directory-to-be-archived > /path/to/backup.tar.gz
podman exec my-container tar -C /path/to/container/data/directory -czf directory-to-be-archived | gpg --symmetric --output /path/to/backup.tar.gz.gpg


CategoryRicottone

Podman/InteractiveUse (last edited 2023-04-06 14:44:11 by DominicRicottone)