Friday, November 15, 2024
Google search engine
HomeGuest BlogsInstall Podman on Ubuntu

Install Podman on Ubuntu

Introduction

Podman is an open-source Linux utility for creating, managing, and running containers and images. The tool is similar to Docker, allowing users to run standalone (non-orchestrated) containers, but it doesn’t require a daemon.

Podman was developed by RedHat, but it is supported by other Linux distributions as well.

In this tutorial, you will learn to install and use Podman on Ubuntu.

This tutorial shows how to install Podman on Ubuntu.This tutorial shows how to install Podman on Ubuntu.

Prerequisites

  • A system running Ubuntu (macOS users, see how to install Podman on macOS.)
  • Access to the terminal (Ctrl + Alt + T).
  • A user account with administrator privileges.

Installing Podman on Ubuntu

The Podman package is available in the official repositories for Ubuntu 20.10 and newer. Older Ubuntu versions require adding the Kubic repository before installation.

Follow the steps below to install Podman:

Install Podman on Ubuntu 20.10 or Newer

1. Open the terminal (Ctrl + Alt + T) and update the system package repository by running:

sudo apt update

2. Install Podman with the following command:

sudo apt -y install podman

The -y flag automatically answers yes to any prompts during the installation.

Install Podman on Ubuntu 20.04 or Earlier

For earlier Ubuntu versions (versions below 20.10), add the Kubic project repository before installing Podman.

Follow the steps below:

1. Source the os-release file to ensure the right repository is added:

. /etc/os-release

Note: The . instructs bash to source the file. In bash, zsh, ksh, the source command can be used instead of .. However, the source keyword isn’t part of the POSIX standard, and it isn’t portable.

2. Run 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"

The > symbol redirects the output to the specified file, adding the repository to the system file. Alternatively, pipe the output into the tee command to write to the specified file.

2. Verify the package integrity by adding a GPG key:

wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${VERSION_ID}/Release.key -O- | sudo apt-key add -
Adding a GPG key to verify Podman package integrity.Adding a GPG key to verify Podman package integrity.

2. Update the package repository with information from the newly added repository:

sudo apt update
Updating system repositories with information from the Kubic repository.Updating system repositories with information from the Kubic repository.

3. Install Podman:

sudo apt -y install podman 

4. Verify the installation by checking the program version:

podman --version
Checking Podman program version.Checking Podman program version.

Important: Ubuntu 22.04 LTS no longer supports Kubic packages. Before upgrading to Ubuntu 22.04, uninstall the packages from Kubic repos.

Using Podman on Ubuntu

Use Podman to search and pull images from repositories such as docker.io and quay.io and run containers. This section shows different examples of using Podman on Ubuntu.

Note: Podman is an alternative to Docker. Read our Podman vs. Docker article to learn the differences between the two container management tools.

Search for Images

Search for images in the available repositories using the following syntax:

podman search [keyword]

For example, to search for mysql images, run:

podman search mysql
Searching for images using Podman.Searching for images using Podman.

Download Images

Download an image using the following syntax:

podman pull [image]

For example, the following command pulls the mysql image from the repository:

podman pull mysql
Downloading an image using podman.Downloading an image using podman.

If the image is available in multiple repositories, Podman prompts you to select which image you want to download.

Note: Dive deeper into the Podman syntax and understand how Podman works with our Podman basics tutorial.

List Downloaded Images

List all downloaded images by running the following command:

podman images
Listing existing images on Ubuntu.Listing existing images on Ubuntu.

The output lists all images currently on the system and image details, including:

  • repository. The origin repository.
  • tag. Any tags associated with the image.
  • image ID. A unique number for each image.
  • created. The image creation date.
  • size. Image size on disk.

Create Containers

Use the following syntax to create a new container from the downloaded image:

podman run [options] [image]

For example, to create a container from the downloaded mysql image, run the following command:

podman  run -dit mysql
  • The -d option forces the detached mode, running the container in the background with the only output being the new container ID.
  • Use the -i option to force the interactive mode, keeping standard input open even in the detached mode.
  • The -t option causes Podman to allocate a pseudo-TTY and attach it to the container’s stdin. This option prevents stdout redirection.
Creating a container from a downloaded image.Creating a container from a downloaded image.

Creating the container outputs the container ID (long form).

List Available Containers

Check all the containers on your machine by running:

podman ps -a
Listing all available containers on Ubuntu.Listing all available containers on Ubuntu.

The -a flag instructs Podman to show all containers, regardless of their state (running or stopped). Enter the command without the -a flag to show only the running containers.

The output includes the following information:

  • container ID. Each container’s unique number (short form).
  • image. The image the container is based on.
  • command. The command for launching the container.
  • created. The time elapsed since the container was created.
  • status. Container uptime or downtime.
  • ports. Includes any forwarded ports.
  • names. A unique name assigned by Podman for each container.

To show a single container, specify the container ID.

Create Image from Container

Create a new image from the running mysql container and upload it to the repository by using this command:

podman commit --author "phoenixNAP" 6f3aeb480f89

The --author flag sets the image author, followed by the container ID.

Output of creating an image from container by setting the image author using --author flag Output of creating an image from container by setting the image author using --author flag

In this example, Podman skips committing this image since no changes have been made to the original image.

Stop or Start a Container

To stop a running container, use the following syntax:

podman stop [container-id]

Start a container using:

podman start [container ID]

Obtain the container ID by listing the available containers.

For example:

Stopping a container using Podman.Stopping a container using Podman.

Alternatively, stop or start the latest container by specifying the --latest flag instead of the container ID. For example:

Stopping or starting the latest created container using Podman.Stopping or starting the latest created container using Podman.

Remove a Container

Remove an existing container with the following syntax:

podman rm [container id]

For example:

Removing a specific container using Podman.Removing a specific container using Podman.

List all available containers to obtain the container ID and then remove the container. Rerunning podman ps -a to list all containers shows that the specified container was removed.

Conclusion

This tutorial showed how to install Podman on Ubuntu and demonstrated some basic use cases. Podman is a great daemonless alternative for Docker and other container management utilities that require a daemon to work.

If you want to test other container management tools, start by installing Docker on Ubuntu and learning the basic commands.

Was this article helpful?
YesNo

RELATED ARTICLES

Most Popular

Recent Comments