Install and Use Podman on Ubuntu 20.04 | Best Setup
In this comprehensive guide, brought to you by Orcacore, we will explore How To Install and Use Podman on Ubuntu 20.04. Podman is a powerful container engine – a crucial tool for modern software development, enabling you to develop, manage, and run containers and container images efficiently. Containers are standardized, self-contained software packages that encapsulate everything needed to run an application, including the application code, runtime, system tools, system libraries, and settings. This "package once, run anywhere" approach has revolutionized software development, making distributed and cloud-based systems easier to deploy, scale, and maintain.
Podman, an open-source project spearheaded by Red Hat, offers a daemonless container engine, differentiating itself from Docker by eliminating the need for a central daemon process. This architecture enhances security and simplifies container management. Furthermore, Podman promotes rootless containers, allowing non-root users to build, run, and manage containers without requiring elevated privileges, a significant security enhancement.
Before we begin the installation, ensure you are logged in to your Ubuntu 20.04 server as a non-root user with sudo
privileges. If you haven’t already, refer to our guide on Initial Server Setup with Ubuntu 20.04 to configure your server appropriately.
Now, let’s dive into the steps to install and use Podman on Ubuntu 20.04.
1. Add Podman Repository to Ubuntu 20.04
The default Ubuntu 20.04 repositories do not include Podman packages. Therefore, we need to manually add the official Podman repository to our system.
First, update your local package index and upgrade existing packages to their latest versions using the following command:
sudo apt update && sudo apt upgrade
This ensures you have the most up-to-date package information and dependencies.
Next, add the Podman repository to your system’s software sources. This tells apt
where to find the Podman packages. Execute the following command:
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
This command adds the specified repository URL to a new file in the /etc/apt/sources.list.d/
directory, which is the standard location for storing custom repository configurations.
To ensure the integrity of the downloaded packages, we need to add the GPG key associated with the Podman repository. Run the following command:
curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/Release.key" | sudo apt-key add -
This command downloads the GPG key from the specified URL and adds it to your system’s keyring. apt
will use this key to verify the authenticity of the packages downloaded from the Podman repository.
Finally, update the system’s package index again to reflect the newly added repository:
sudo apt update
2. Install Podman on Ubuntu 20.04
With the Podman repository added and the GPG key imported, we can now proceed with the installation of Podman.
Execute the following command to install Podman and its dependencies:
sudo apt install podman -y
The -y
flag automatically confirms the installation, bypassing the need for manual confirmation.
Verify the installation by checking the Podman version:
podman -v
This command displays the installed Podman version. You should see output similar to the following:
**Output**
podman version 3.4.2
To obtain comprehensive information about Podman, including its configuration, storage settings, and dependencies, use the following command:
podman info
This command generates a detailed report containing valuable insights into your Podman installation.
[See Image Above]
3. How To Use Podman on Ubuntu 20.04?
Now that you have successfully installed Podman on your Ubuntu 20.04 server, let’s explore its basic usage through practical examples.
Search and pull images with Podman
Similar to Docker, Podman allows you to search for container images from various registries using the command line interface.
For example, to find available Ubuntu images, execute the following command:
podman search ubuntu
This command queries the configured container registries and displays a list of matching images.
To download a specific image, use the podman pull
command followed by the image name. For example, to pull the official Ubuntu image, run:
podman pull ubuntu
This command downloads the specified image from the registry and stores it locally on your system.
List all Images with Podman
To view a list of all images available on your system, use the podman images
command:
podman images
This command displays a table containing information about each image, including its repository, tag, image ID, creation date, and size.
[See Image Above]
Create a Container with Podman
Once you have downloaded the necessary image, you can create a container based on that image. For instance, to create a container using the Ubuntu image, execute the following command:
podman run -dit --name orca ubuntu
Note: The --name
parameter allows you to assign a user-friendly name to the container. In this case, we’ve named the container "orca". The -dit
flags run the container in detached mode (in the background), allocate a pseudo-TTY, and keep STDIN open even if not attached.
To access the container’s command line interface, use the podman attach
command followed by the container name:
podman attach orca
This command attaches your terminal to the container’s console, allowing you to interact with the container’s operating system.
You will notice that your command prompt changes to reflect the container ID:
sam@048260657f81:/#
To start a stopped container, use the podman start
command followed by the container ID or name:
podman start container-id or name
Similarly, to stop a running container, use the podman stop
command:
podman stop container-id or name
For more detailed information and advanced usage scenarios, consult the official Podman Documentation page.
Conclusion
In conclusion, installing and using Podman on Ubuntu 20.04 is a straightforward process that provides a secure, daemonless alternative to Docker for managing containers. Its familiar commands and rootless operation enhance security and ease of use. Understanding How To Install and Use Podman on Ubuntu 20.04 empowers you to leverage containerization technology effectively.
Here are some additional articles you might find interesting:
- How To Install KVM on Ubuntu 20.04
- Install and Use 7-Zip on Ubuntu 20.04
- How To Set up PostgreSQL on Ubuntu 20.04
- Install and Configure Zabbix on Ubuntu 20.04
Alternative Solutions for Container Management on Ubuntu 20.04
While the article focuses on Podman, let’s explore two alternative approaches to container management on Ubuntu 20.04: Docker and LXD/LXC.
1. Docker:
Docker is the most popular containerization platform and serves as a direct competitor to Podman. It utilizes a client-server architecture with a central daemon process (dockerd) managing containers. While Podman offers daemonless and rootless features for enhanced security, Docker boasts a more mature ecosystem, extensive documentation, and a vast community.
To install Docker on Ubuntu 20.04:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world
Docker provides similar commands to Podman for image management and container creation (e.g., docker search
, docker pull
, docker run
, docker images
). The key difference lies in the architecture and the need for a daemon process.
2. LXD/LXC:
LXD (Linux Container Daemon) is a system container manager built on top of LXC (Linux Containers). LXC offers a more lightweight virtualization approach compared to Docker and Podman, as it leverages the kernel’s built-in containerization features directly. LXD provides a higher-level abstraction for managing LXC containers, offering features like snapshots, live migration, and network management.
To install LXD on Ubuntu 20.04:
sudo snap install lxd
sudo lxd init
LXD uses the lxc
command-line tool for managing containers. Here’s an example of creating and starting an Ubuntu container with LXD:
lxc launch ubuntu:20.04 mycontainer
lxc list
lxc exec mycontainer bash
LXD/LXC are particularly well-suited for running full operating systems within containers, offering near-native performance. However, they may require more configuration and management compared to Docker and Podman, especially for complex application deployments.