How to Install Podman on Ubuntu 20.04 and 22.04

RedSwitches
9 min readAug 13, 2024

--

how install podman on ubuntu

Are you tired of the complexities of container management?

Containers have revolutionized software development and deployment, offering isolation, portability, and efficiency. However, managing them can be resource-intensive and challenging.

What if you can have a great solution to this problem?

Podman, an open-source Linux tool that helps create, manage, and run containers and images is the solution. This open-source tool is designed to be a drop-in replacement for the Docker daemon, but without requiring root privileges to run.

In this tutorial, we will discuss how to install Podman in Ubuntu 20.04 and 22.04.

Let us start with a short introduction to Podman.

What is Podman?

Podman is an open-source tool for managing containers, images, and pods on Linux systems. What sets it apart from other container engines like Docker is its daemon-less architecture, meaning, it doesn’t require a separate background process to run, making it more lightweight and secure.

Podman allows users to manage containers without root privileges, further boosting security and flexibility. It completely supports Open Container Initiative (OCI) standards, ensuring compatibility with a wide range of container technologies.

Let us now move on to the core part of our tutorial–how to install Podman on Ubuntu 20.04 and 22.04.

How to Install Podman on Ubuntu 20.04 and 22.04

Ubuntu 20.04 and 22.04 are Long Term Support (LTS) releases that offer stability and extended support. Podman is an important option for building and deploying containerized applications because of its reputation as an industry-standard containerization solution.

Before we move into the installation process, let us quickly examine the prerequisites.

The Prerequisites

Before you dive into the installation, ensure you have the following.

  • A server or desktop running Ubuntu 20.04 or 22.04 (Ubuntu 20.10 and newer or Ubuntu versions earlier to 20.10)
  • A user account with sudo or administrative privileges
  • Terminal or command line access

The Podman package is available in the official repositories of Ubuntu 20.10 and newer. If you have an older Ubuntu version, you need to add the Kubic repository before you can install Podman.

In this tutorial, we will demonstrate how to install Podman on both versions of Ubuntu.

Type #1: Install Podman on Ubuntu 20.10 or Newer

If you want to install Podman on Ubuntu 20.10 and newer, open the terminal or press Ctrl + Alt + T.

Next, update your system package repository with the following command:

# sudo apt update

This command synchronizes package information with the repositories, ensuring you have the latest package available.

Once you have updated your system repository, you can install Podman using the following command:

# sudo apt -y install podman

Here, the -y flag automatically agrees to any prompts during the installation.

Type #2: Install Podman on Ubuntu 20.04 or Earlier

If you are installing Podman on Ubuntu versions less than 20.10, you need to add the Kubic project repository.

Follow the steps below to install Podman on Ubuntu 20.04 or earlier version:

First, load the os-release file to make sure the right repository is added.

# . /etc/os-release

Note: The . in the command implies bash to load the file. You can also use source instead of . in bash, zsh, and ksh. Note that the source might not function in every environment, as it is not included in the POSIX standard.

Next, enter the following command to add the Kubic repository:

# sudo sh -c “echo ‘deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /’ > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list”

Here,

>: Directs the output to a specified file, adding the repository to your system file. Alternatively, you can also write the output to the file using the tee command.

Once you have added the Kubic repository, add a GPG key to verify the integrity of the package.

# wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${VERSION_ID}/Release.key -O- | sudo apt-key add -

Refresh the package repository to include information from the new repository

Next, install Podman by executing the following command:

# sudo apt -y install podman

Verify if you have successfully installed the Podman.

# podman — version

If the output is the right program version, you have successfully installed Podaman.

Important: Kubic packages are no longer supported by Ubuntu 22.04 LTS. Make sure to remove the Kubic packages before upgrading to Ubuntu 22.04.

How to Use Podman on Ubuntu

With Podman, you can search for and download images from repositories like docker.io and quay.io, and run containers.

Let’s discuss several use cases that highlight the versatility of Podman in Ubuntu environments.

Use Case #1: Search for Images

Podman allows users to search and pull images from repositories, giving access to a wide range of pre-built container images for various applications and services.

If you want to look for images in public repositories, execute the following command:

# podman search [keyword]

For instance, to look for images of MySQL, run the following command:

# podman search mysql

Use Case #2: Download Images

We recommend executing the following command to download an image.

# podman pull [image]

For instance, to download the MySQL image from the repository, run:

# podman pull mysql

If the image is found in multiple repositories, you will be prompted to choose one to download.

Use Case #3: List Downloaded Images

Downloading the image is not enough to run the applications in containers. You need to be able to view the images before you can make the choice.

To list all the images you’ve downloaded, use this command:

# podman images

The output displays all images on your system along with details like:

  • Repository: The source of the image.
  • Tag: Any labels or versions of the image.
  • Image ID: A unique identifier for each image.
  • Created: The date when the image was created.
  • Size: The size of the image on your disk.

Use Case #4: Create Containers

Starting a new container from a downloaded image offers several advantages that enhance efficiency, consistency, and ease of deployment in containerized environments. If you want to start a new container from a downloaded image, run:

# podman run [options] [image]

For instance, use the following command to turn the MySQL image you downloaded into a container:

# podman run -dit mysql

Here,

-d: Display the container ID.

-i: Keeps the standard input open, even if the container is running in the background.

-t: Sets a virtual terminal for the container’s input, preventing output from being redirected.

Creating the container will display a long container ID.

Use Case #5: List Available Containers

To see all the containers on your machine, use the following command:

# podman ps -a

Here,

-a: Implies Podman to display all containers, whether they are running or not. The command will only display the active containers if -a is omitted.

The output includes:

  • Container ID: A unique short number for each container.
  • Image: The image that the container is based on.
  • Command: The command used to start the container.
  • Created: How long ago the container was created.
  • Status: Whether the container is running or stopped.
  • Ports: Any ports that are forwarded.
  • Names: A unique name assigned to each container by Podman.

To see details for a specific container, use its container ID.

Use Case #6: Create Image from Container

If you want to make significant changes to a running container or want to capture a specific state of a container for reproducibility, you need to create a new image from the container.

We recommend using the following command to create a new image from a container:

# podman commit [container_id] [new_image_name]

For instance, to create a new image from a running MySQL container and upload it to the repository, run:

# podman commit — author “Redswitches” ca66b3b8bfc5

Here,

— author: Specifies the image author.

In this example, Podman won’t create a new image as there are no changes from the original image.

Use Case #7: Stop or Start a Container

To stop a running container, use the following command:

# podman stop [container-id]

On the other hand, if you need to start the container, run:

# podman start [container ID]

Get the container ID by listing the containers.

Instead of using the container ID, you can also use the — latest flag. For instance:

# podman stop — latest

Use Case #8: Remove a Container

When a container is no longer needed or is consuming excessive resources, you may have to remove it.

To remove a container, use the following command:

# podman rm [container id]

By removing unnecessary containers, you can free up system resources and maintain a clean container environment.

Conclusion

Installing Podman on Ubuntu 20.04 or 22.04 is a straightforward process that enhances your ability to manage containers without relying on a central daemon.

By following the steps to add the Kubic repository or use the default package sources, you can easily set up Podman and start using it for container management.

Whether you’re working with newer or older versions of Ubuntu, Podman offers a flexible and powerful alternative to Docker, making it a valuable tool for container-based workflows.

FAQs

Q. What is Podman and how does it relate to Docker?
Podman is an open-source tool for managing containers and images. It offers similar functionality to Docker but does not require a central daemon. It can be used as a drop-in replacement for Docker in many cases, often referred to as Podman for Docker.

Q. How do I install Podman on Ubuntu 20.04 or 22.04?
To install Podman, you need to update your package list and install it from the official repositories. For Ubuntu 22.04, you might use the default package sources, while for older versions, you may need to add the Kubic repository. Follow the Podman installation instructions for detailed steps.

Q. What are the prerequisites for installing Podman?
You need a system running Ubuntu 20.04 or 22.04, root privileges to install packages, and access to the terminal. Ensure that you have updated your package list before starting the installation.

Q. How can I manage container images with Podman?
You can use Podman to pull, search, and manage container images similarly to Docker. For example, to pull an image, use podman pull [image-name], and to list all images, use podman images.

Q. Can I use Docker commands with Podman?
Podman supports a subset of Docker commands, making it easier for Docker users to transition. However, not all Docker commands are available in Podman. For full compatibility, use podman in place of docker where applicable.

Q. How do I handle Docker images with Podman?
Podman can manage Docker images seamlessly. You can pull Docker images from Docker Hub using Podman and run them just like you would with Docker.

Q. What should I do if I need to manage containers as a non-root user?
Podman supports running containers as a non-root user. Use the sudo podman info command to check if Podman is set up correctly for non-root use. This can help with running containers without needing root privileges.

Q. How do I remove a container with Podman?
To remove a container, first list all containers to get the container ID with podman ps -a. Then use the command podman rm [container-id] to remove the specified container.

Q. How can I transfer containers between systems?
To transfer containers, you can save the container image to a file using podman save, then move the file to the target system and load it using podman load. This method allows for container transfer across different environments.

Q. What are secure containers, and how does Podman handle them?
Secure containers are designed with enhanced security features to protect against vulnerabilities. Podman provides options to configure and run secure containers, ensuring that containers are isolated and adhere to security best practices.

--

--

RedSwitches

RedSwitches: Global hosting provider offering Dedicated Servers, IaaS, Managed Solutions & Smart Servers in 20 locations with latest hardware and networks.