Podman is an open-source tool for managing containers, images, volumes, and pods (group of containers). It’s used the libpod library APIs for managing container lifecycles and supports multiple container image formats, including OCI (Open Container Initiative) and Docker images.

Podman is OCI (Open Container Initiative) compliance container engine. It’s compatible with the Docker CLI interface and allows you to run container rootless (running container without root privileges). Podman was released as part of Red Hat Enterprise Linux, designed to be the next generation of Linux container tool with faster experimentation and development of features.

For this tutorial, you will learn how to install Podman on the Ubuntu 20.04 system. You will be installing Podman and learn the basic usages of podman for managing Docker containers, images, and volumes.

Prerequisites

  • An Ubuntu 20.04 server – ensure all packages are the latest version, to get rid of deprecated dependencies and lead you to an error during the installation.
  • A user with root privileges, or user root – for installing new packages and change configuration system-wide.

Installing Podman on Ubuntu 20.04

At first, you will be adding a Third-party repository and key for installing podman on the Ubuntu 20.04 system.

1. Execute the following command to export environment variables on the ‘/etc/os-release‘ file.

. /etc/os-release

2. Add the podman repository with stable release and add the GPG key to your system using the command below.

echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list

curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key" | sudo apt-key add -

3. Update/refresh Ubuntu repositories and upgrade all packages to the latest version.

sudo apt update

sudo apt -y upgrade

<img alt="Add podman repository ubuntu 20.04" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/1-add-repository-podmn-ubuntu20.png61e17fdc837ba.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="171" loading="lazy" src="data:image/svg xml,” width=”750″>

4. After that, install podman using the apt command below.

sudo apt install podman

Type ‘y‘ and press ‘Enter‘ to continue the installation.

<img alt="Installing Podman on Ubuntu 20.04" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/2-install-podman-ubuntu20.png61e17fdcb26b8.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="220" loading="lazy" src="data:image/svg xml,” width=”750″>

5. After installation completes, verify the podman version using the following command.

podman version

Below is the similar output you will get.

<img alt="Check podman version" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/3-check-podman-version.png61e17fdce9e56.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="200" loading="lazy" src="data:image/svg xml,” width=”669″>

As can be seen, you’ve installed podman v3.3.1 compiled with Go 1.16 for the Linux architecture amd64 (64-bit).

Creating New User and Run hello-world Container

Podman allows you to run containers under the user without root privileges. For this stage, you will be adding a new user and run the container ‘hello-world’ based on the Docker image.

1. Execute the following command to add a new user ‘johndoe’.

useradd -m -s /bin/bash johndoe

passwd johndoe

Type new password for user ‘johndoe‘.

2. Next, log in as user ‘johndoe’ and run the container based on the Docker image ‘hello-world’.

Log in as user ‘johndoe‘.

su - johndoe

Run new container based on Docker image ‘hello-world‘ using podman command.

podman run hello-world

You will be asked for which container registry you want to use, choose the ‘docker.io’ container registry and you will see a similar output as below.

<img alt="Podman run hello-world container" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/4-podman-run-hello-world-container.png61e17fdd29718.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="419" loading="lazy" src="data:image/svg xml,” width=”750″>

3. To verify your container and images on the local machine, execute the command below.

podman ps -a

podman images

You will see a new container is created and the current status is ‘Exited‘. The container is based on the ‘hello-world‘ Docker image.Advertisement

<img alt="Podman check container and images" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/5-podman-checkc-images-and-container-status.png61e17fdd5e24c.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="144" loading="lazy" src="data:image/svg xml,” width=”750″>

Podman Basic Usage

With this guide, you will learn how to use podman for managing containers, images, and volumes. You will learn the basic command of podman for managing container, and commands you will be using for this guide is 100% same as Docker CLI command.

1. To find container images compatible with the podman, execute the podman command below.

podman search nginx

And you will see a list of container images from the default Docker image registry and Quay images registry.

Choose the container images ‘nginx’ from the Docker registry and download to your local machine using the podman command below.

podman pull nginx:alpine

Choose the container registry ‘docker.io‘ and the download process for the Nginx container image will begin.

<img alt="Podman downloaad container images" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/6-podman-download-images.png61e17fdd9cdd7.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="276" loading="lazy" src="data:image/svg xml,” width=”750″>

2. To check available container images on your local machine, execute the podman command below.

podman images

And you will see two images – hello-world and nginx images.

<img alt="Check images on local machine with podman" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/7-podman-check-images-local.png61e17fde05909.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="136" loading="lazy" src="data:image/svg xml,” width=”750″>

3. Next, to start and run a new container based on image ‘nginx:alpine‘, execute the podman command with the option ‘run‘ as below.

podman run -it --rm -d -p 8080:80 --name web nginx:alpine

Some options you must know:

  • -i or –interactive – keep the container STDIN open even if unattached.
  • -t or –-tty – allocates a pseudo-terminal that connects your terminal with the container’s STDIN and STDOUT.
  • –rm – automatically remove the container when the container is exited or stopped.
  • -d – running the container in the background, deattach the container after it’s running.
  • -p 8080:80 – map the port between container and host system. The port ’80’ on the container is mapped to the host system port ‘8080’.
  • –name web – specify the new container name as ‘web’.
  • nginx:alpine – the image we use is ‘nginx:alpine’.

You will see the random string and number of your running container. Verify your running container using the podman command below.

podman ps

You will see the output as below.

<img alt="Start and run container with podman" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/8-start-run-container-using-podman.png61e17fde4b97f.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="115" loading="lazy" src="data:image/svg xml,” width=”750″>

The container status is ‘Up‘ and exposes the port TCP port ‘8080‘ on the host machine.

Open your web browser and visit your server IP address with port ‘8080‘ as below.

http://192.168.1.15:8080/

And you will see the default ‘index.html’ age of your nginx container.

<img alt="Container web based on Nginx image is running" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/9-verify-nginx-podman-container.png61e17fdeccf0e.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="331" loading="lazy" src="data:image/svg xml,” width=”750″>

4. Additionally, you can check logs of your container using the ‘logs‘ option as below.

podman logs web

<img alt="Podman checkc logs" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/10-podman-check-logs-ccontainer.png61e17fdf3347e.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="196" loading="lazy" src="data:image/svg xml,” width=”750″>

Or you can specify the last number lines of the container log with the ‘–tail‘ option as below.

podman logs --tail 10 web

<img alt="Podman check latest logs" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/11-podman-check-logs-container-with-tail-option.png61e17fdf862d3.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="137" loading="lazy" src="data:image/svg xml,” width=”750″>

5. Now you can stop the running container using the podman option ‘stop‘ as below.

podman stop web

Your container ‘web’ will be stopped. Check using the command below.

podman ps

podman ps -a

And you will see similar output as below.

<img alt="stop container podman" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/12-stop-container-podman.png61e17fe051284.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="141" loading="lazy" src="data:image/svg xml,” width=”750″>

The container ‘web’ is stopped and automatically deleted because you’re using the option ‘–rm’ on your podman command.

6. Next, you will learn how to use the custom volume to change the default ‘index.html’ on the new container.

Create a new directory ‘~/data‘ and the ‘index.html‘ file using the following command.

mkdir -p ~/data/

nano ~/data/index.html

Copy and paste the HTML script below.







 

  Welcome to Container Nginx





 

Hello from Nginx container - Managed with Podman





Press the ‘Ctrl x‘ button, type ‘y‘, then press ‘Enter‘ to save the configuration and exit.

Now execute the following podman command to run the new container with custom volume.

podman run -it --rm -d -p 8080:80 --name web -v ~/data:/usr/share/nginx/html nginx:alpine

An option you must know:

  • -v – specify the volume for your container. The ‘~/data‘ directory will be mounted to the new container directory ‘/usr/share/nginx/html‘.

Now execute the following command to verify the running container.

podman ps

You will see the new container ‘web‘ in on the status ‘Up‘.

<img alt="Using custom volume with podman" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/13-start-container-with-custom-volume-podman.png61e17fe0b6b97.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="135" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, open your web browser and type your server IP address with port ‘8080‘.

http://192.168.1.15:8080/

And you will see the custom index.html page you’ve created on top, which means the ‘~/data‘ directory is mounted to the ‘web‘ container.

<img alt="Container web with custom index.html provided by volume" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/14-container-web-running-with-custom-volume.png61e17fe1054b0.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="267" loading="lazy" src="data:image/svg xml,” width=”750″>

7. Next, you can log in to the running container with the option ‘exec‘ and executing the ‘sh’ shell.

Make sure your container ‘web‘ is running using the following command.

podman ps

Now execute the podman command below to log in to the container ‘web’.

podman exec -it web /bin/sh

Check the hostname of the container ‘web’.

hostname

Check the IP address and routing table of container ‘web’.

ip a

route -n

Now type ‘exit‘ to log out from the container ‘web‘.

<img alt="Podman log in to the container" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/15-podman-attach-to-running-container.png61e17fe1bed18.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="317" loading="lazy" src="data:image/svg xml,” width=”750″>

8. Now clean up your environment using the following command.

Stop the container ‘web‘ using the podman command below.

podman stop web

Remove all containers with the status ‘Exited’ using the podman command below.

podman rm $(podman ps --filter "status=exited" -q)

<img alt="Cleanup exited container with podman" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/01/echo/16-cleanup-remove-exited-container.png61e17fe20e07b.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="211" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

Congratulation! You have successfully installed Podman on Ubuntu 20.04 system. Also, you’ve learned the basic usage of podman for downloading container images, run the container, checking container status, logs, and basic usage of podman for managing volume. For the next step, you can try to create your custom images with OCI specifications for your application push/upload to the container registry.