Podman Notes

All Container related commands can be found here.

1. Podman Installation

  • Install guide is here.

1.1. Install Podman

1.1.1. RHEL Installation

  1. Install EPEL

    sudo dnf install -y epel-release
  2. Install podman and podman-compose:

    sudo dnf install -y podman podman-compose

1.1.2. Ubuntu Installation

  1. Install

    sudo apt update && sudo apt -y install podman podman-compose

1.2. Config

  • Pods do not start on their own when the system is rebooted.
    This can be fixed with systemd integration which will allow Pods to be turned into services and controlled by the systemctl commands.

    Only do these steps once.
    1. First, turn on the container_manage_cgroup boolean to run containers with systemd:

      non Ubuntu OS
      sudo setsebool -P container_manage_cgroup on
    2. Create the systemd unit template file entry with:

      sudo podman-compose systemd -a create-unit
    3. Confirm creation of the template:

      Run
      cat /etc/systemd/user/podman-compose@.service
      Expand for sample result
      [Unit]
      Description=%i rootless pod (podman-compose)
      
      [Service]
      Type=simple
      EnvironmentFile=%h/.config/containers/compose/projects/%i.env
      ExecStartPre=-/usr/bin/podman-compose up --no-start
      ExecStartPre=/usr/bin/podman pod start pod_%i
      ExecStart=/usr/bin/podman-compose wait
      ExecStop=/usr/bin/podman pod stop pod_%i
      
      [Install]
      WantedBy=default.target
    4. For all users that will run pods.

      1. Enable linger
        This will allow containers to continue to run even if the user is logged out.

        sudo loginctl enable-linger 'mattosd'
      2. In the user’s home dir, run

        non Ubuntu OS
        restorecon -R
      3. Start and enable the user‑level socket

        systemctl --user enable --now podman.socket

2. Podman Container Commands

All commands can be found here.

2.1. Run a Container

podman run -dt -p 8080:80/tcp docker.io/library/httpd

2.2. Listing of running containers

  1. Run this command

    podman ps -a
  2. Sample output

    CONTAINER ID  IMAGE                           COMMAND           CREATED         STATUS         PORTS                 NAMES
    0c4b6f2a8522  docker.io/library/httpd:latest  httpd-foreground  26 seconds ago  Up 26 seconds  0.0.0.0:8080->80/tcp  recursing_babbage

2.3. View Container Log

podman inspect -l

3. Podman Image Commands

  • List images

    All images
    podman images
    Dangling images
    podman images -f dangling=true
  • Remove images

    Remove dangling images
    podman image prune
    Remove images not currently in use
    podman image prune -a

4. Updating a Pod

  • The following will update all containers within a Pod

    1. cd into the project folder containing the Pod’s compose.yaml file

      Example
      cd /home/repo-pod-master/pod-ai
    2. Pull the latest Pod images

      Execute the pull command
      podman-compose pull
    3. Recreate the Pod

      Force recreate
      podman-compose up -d --force-recreate
    4. Prune any dangling images

      This will delete any images that are not currently in use
      Force recreate
      podman image prune

5. Podman-Compose Commands

5.1. Stats

  • This is like a top command for pods

    podman-compose stats

5.2. Podman-Compose systemd Commands (RHEL)

5.2.1. Create SystemD Commands

  • For each container:

    The following will only work if the pod has run at least once via
    podman-compose up -d

    1. cd into the project folder containing the Pod’s compose.yaml file

    2. Shutdown the pod if it’s already running

      podman-compose down
    3. Register Unit File

      podman-compose systemd -a register
    4. Enable and Start up the Pod

      systemctl --user enable --now 'podman-compose@<pod name>'
      Example
      systemctl --user enable --now 'podman-compose@pod-ai'
    5. Now you can use systemd commands to stop, start, and get the status of the pod container:

      Start Example
      systemctl --user start 'podman-compose@pod-ai'
      Status Example
      systemctl --user status 'podman-compose@pod-ai'
      Stop Example
      systemctl --user stop 'podman-compose@pod-ai'

5.2.2. Remove SystemD Commands

  1. cd into the project folder containing the Pod’s compose.yaml file

  2. Stop the service.

    Example
    systemctl --user stop podman-compose@pod-uac-server.service
  3. Disable the service.

    Example
    systemctl --user disable podman-compose@pod-uac-server.service
  4. Restart the systemd daemon.

    Example
    systemctl --user daemon-reload