Podman Notes

All Container related commands can be found here.

1. Podman Installation

1.1. RHEL

  1. Install with:

    sudo dnf install -y podman podman-compose
  2. Enable:

    systemctl --user enable --now podman.socket
    • Install guide is here.

1.2. Ubuntu

Do not install on Ubuntu until a solution is found for podman-compose!

1.2.1. Podman-compose Installation on Ubuntu

The official podman-compose package available in the official repositories is outdated!

Do not execute the following command:

sudo apt install podman-compose
  1. First install pip

    sudo apt install -y python3-pip
  2. Install podman-compose

    pip install podman-compose --break-system-packages
  3. Update path

    export PATH="$HOME/.local/bin:$PATH"

1.2.2. Podman Installation on Ubuntu

The official podman package available in the official repositories is outdated!

Do not execute the following two commands:

sudo apt-get update
sudo apt-get -y install podman

Instead, follow the instructions below:

  1. First install Homebrew.

  2. Now install via Homebrew:

    brew install podman
  3. To start podman now and restart at login:

    brew services start podman
  4. Install newuidmap and newgidmap (from the uidmap package) to map user/group IDs

    sudo apt install -y uidmap
  5. Make podman executable

    chmod +x $(which podman)

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. 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

4. Podman-Compose Commands

4.1. Stats

  • This is like a top command for pods

    podman-compose stats

4.2. Podman-Compose systemd Commands (RHEL)

4.2.1. Initialization

  • On RHEL systems, 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:

    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

      restorecon -R

4.2.2. 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'

4.2.3. 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