Search code examples
podman

How to list rootless containers of ALL the users?


Is there a command to show the containers and images present in the server? That means for root and all the users (rootless containers)?

su -
podman container ps --all

shows only root's containers.

I expected root to be able to see all the other containers.


Solution

  • I don't think there is any command to list all containers for all users, but you could list all containers for an arbitrary user:

    sudo systemd-run --machine=username@ --quiet --user --collect --pipe --wait podman container ps --all
    

    (a recent version of systemd is needed for the command above).

    You could also use machinectl

    $ sudo -i
    # machinectl shell username@
    Connected to the local host. Press ^] three times within 1s to exit session.
    $ podman container ps --all
    

    Both executables belong to the systemd project.

    $ rpm -qf /usr/bin/systemd-run
    systemd-249.9-1.fc35.x86_64
    $ rpm -qf /usr/bin/machinectl 
    systemd-container-249.9-1.fc35.x86_64
    $ cat /etc/fedora-release 
    Fedora release 35 (Thirty Five)
    

    As to why not use su see

    Quote Why can't I run rootless Podman containers when I log into a user via sudo or su? from https://www.redhat.com/sysadmin/sudo-rootless-podman

    See also https://github.com/containers/podman/blob/main/troubleshooting.md#30-podman-run-fails-with-erro0000-xdg_runtime_dir-directory-runuser0-is-not-owned-by-the-current-user-or-error-error-creating-tmpdir-mkdir-runuser1000-permission-denied