Podman

Podman is a daemonless container engine. Most of the command syntax is the same as docker.

Podman Compose is similar to Docker Compose.

Prune Containers

podman stop --all
podman image rm --all
podman system prune --all --force --external

Installing on macOS/Windows

  • Example specifying number of CPUs, available memory, and disk:
    podman machine init --cpus 4 --memory 10240 --disk-size 100
  • Example also mounting a host filesystem for later volume mounts:
    podman machine init --cpus 4 --memory 10240 --disk-size 100 -v /tmp:/tmp/host
    Then run with -v /tmp/host:/tmp/host
    • On Windows+WSL, -v on the machine init is not needed as /mnt/$DRIVE are automatically mounted (e.g. /mnt/c)
  • On recent versions of podman on macOS on ARM, if there is a hang on podman machine start, try re-creating the machine with:
    export CONTAINERS_MACHINE_PROVIDER=applehv
  • To use a different version of CoreOS, find a build on the build browser, download the "QEMU" file and point to the downloaded image with --image-path. Cached images are stored in ~/.local/share/containers/podman/machine/qemu/

Running on macOS/Windows

podman machine start

On Windows+WSL, you can enter the machine with wsl -d podman-machine-default

Status on macOS/Windows

$ podman machine ls
NAME                     VM TYPE     CREATED             LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default*  qemu        About a minute ago  Currently running  4           8.59GB      53.69GB
$ podman version
Client:
Version:      3.4.0
API Version:  3.4.0
Go Version:   go1.17.1
Built:        Thu Sep 30 11:44:31 2021
OS/Arch:      darwin/amd64

Server:
Version:      3.3.1
API Version:  3.3.1
Go Version:   go1.16.6
Built:        Mon Aug 30 13:46:36 2021
OS/Arch:      linux/amd64

SSH on macOS/Windows

$ podman machine ssh
[...]
[core@localhost ~]$ uname -a
Linux localhost 5.14.9-200.fc34.x86_64 #1 SMP Thu Sep 30 11:55:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Root podman on macOS/Windows

By default, the podman connection is a non-root connection:

$ podman system connection list
Name                         Identity                                  URI
podman-machine-default*      /Users/kevin/.ssh/podman-machine-default  ssh://core@localhost:59679/run/user/1000/podman/podman.sock
podman-machine-default-root  /Users/kevin/.ssh/podman-machine-default  ssh://root@localhost:59679/run/podman/podman.sock

To switch to a root podman, update the default connection:

podman system connection default podman-machine-default-root

To switch back to a non-root podman, update the default connection:

podman system connection default podman-machine-default

Capabilities

  • List capabilities of a container: podman exec -it $CONTAINER capsh --print

Cross-compile on macOS

  1. Install qemu-user-static (CoreOS uses rpm-ostree instead of dnf/yum):
    podman machine ssh "sudo rpm-ostree install qemu-user-static"
  2. Stop the machine (do not use systemctl reboot as suggested in the output of the above command):
    podman machine stop
  3. Start the machine:
    podman machine start
  4. Try to run some other architecture; for examples, Fedora supports various architectures:
    $ podman run --rm --platform linux/amd64 -it fedora uname -m
    x86_64
    $ podman run --rm --platform linux/arm64/v8 -it fedora uname -m
    aarch64
    $ podman run --rm --platform linux/ppc64le -it fedora uname -m
    ppc64le
    $ podman run --rm --platform linux/s390x -it fedora uname -m
    s390x
    In one command:
    for p in linux/amd64 linux/arm64/v8 linux/ppc64le linux/s390x; do podman run --rm --platform $p -it fedora uname -m; done