Podman: Install and Manage Containers

podman cpynet

Podman is an open-source tool used to create, manage, and run containers. It offers a user experience similar to Docker but does not require a constantly running background daemon. This makes Podman a lighter and more secure option compared to Docker.

Benefits of Podman

No Daemon Required

Unlike Docker, Podman does not need a continuously running service in the background. This feature makes it more resource-efficient, as it only runs processes when necessary, without the overhead of an always-on daemon. This design choice improves system performance and makes Podman a great option for both development and production environments.

Rootless Operation

Podman can operate without root privileges, providing a significant security advantage. Containers traditionally require root access to manage and control, which opens up potential vulnerabilities. By running containers in a rootless mode, Podman reduces the attack surface, enhancing security by limiting the access level of processes.

Docker Compatibility

Podman is largely compatible with Docker’s command-line interface (CLI). This means that Docker users can easily transition to Podman with minimal changes to their workflows. Podman allows users to leverage their existing Docker expertise without the need for extensive retraining or modification of existing Docker-based processes.

Container Orchestration

Podman supports Kubernetes-compatible YAML files, which is essential for container orchestration. This allows Podman to seamlessly integrate into larger Kubernetes-based infrastructures, making it a solid choice for container management at scale. Whether managing a single container or orchestrating complex multi-container applications, Podman provides the flexibility needed to work in various environments.


Installing Podman

The installation of Podman depends on the operating system being used. Below is a detailed guide on how to install Podman on the most common platforms.

Installing Podman on Ubuntu

To install Podman on Ubuntu, follow these steps:

  1. Add the Repository:
   sudo sh -c "echo 'deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/x${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
   wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/x${VERSION_ID}/Release.key -O Release.key
   sudo apt-key add - < Release.key
   sudo apt-get update
  1. Install Podman:
   sudo apt-get -y install podman

Installing Podman on CentOS/RHEL

For CentOS or RHEL, the steps are as follows:

  1. Add the Repository:
   sudo yum -y install epel-release
   sudo yum -y install https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/CentOS_8/devel:kubic:libcontainers:stable.repo
  1. Install Podman:
   sudo yum -y install podman

Installing Podman on Fedora

Fedora generally includes Podman in its default package repositories. To install the latest version:

sudo dnf -y install podman

Installing Podman on macOS

On macOS, you can use the Homebrew package manager to install Podman.

  1. Ensure Homebrew is Installed:
   /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install Podman:
   brew install podman
  1. Start Podman:
   podman machine init
   podman machine start

Installing Podman on Windows

To use Podman on Windows, the Windows Subsystem for Linux (WSL) is required.

  1. Install WSL: Open PowerShell as an administrator and run the following command:
   wsl --install

Restart your computer after the installation.

  1. Install a Linux Distribution: From the Microsoft Store, download and install a Linux distribution, such as Ubuntu.
  2. Install Podman in the Linux Distribution: Follow the Ubuntu installation steps listed above to install Podman in the WSL environment.
  3. Start Podman: Check the version of Podman by running:
   podman --version

Basic Podman Commands

Podman operates similarly to Docker in terms of its command structure. Below are some basic Podman commands to get you started.

Running a Container

To run a container with Podman:

podman run -it --name mycontainer ubuntu bash

This command starts a new container using the ubuntu image and opens an interactive terminal session (bash) inside the container.

Listing Running Containers

To list all running containers:

podman ps

Listing All Containers

To list all containers (including stopped ones):

podman ps -a

Stopping a Container

To stop a running container:

podman stop mycontainer

Removing a Container

To remove a stopped container:

podman rm mycontainer

Listing Images

To list all available container images:

podman images

Pulling an Image

To download a container image (e.g., Ubuntu):

podman pull ubuntu

Removing an Image

To remove an image:

podman rmi ubuntu

Running Your First Container with Podman

Running your first container with Podman is straightforward. Here’s a step-by-step guide using the ubuntu image.

Step 1: Pull the Ubuntu Image

podman pull ubuntu

Step 2: Run the Container

podman run -it --name first_container ubuntu bash

This will launch an interactive terminal session inside the container, using the bash shell.

Step 3: Perform Operations Inside the Container

You can now run various commands inside the container, such as installing software:

apt update
apt install -y nginx

Step 4: Exit the Container

Once you’re done, exit the container:

exit

Step 5: List Containers

To check the status of your containers, use:

podman ps -a

Image Management with Podman

Podman provides powerful tools for managing container images. Here are some common tasks:

Listing Existing Images

To view all the available container images on your system:

podman images

Pulling a New Image

To pull a new image, such as the alpine image:

podman pull alpine

Tagging an Image

To tag an image for easier reference:

podman tag alpine myrepo/alpine:latest

Pushing an Image

To push an image to a remote registry:

podman push myrepo/alpine:latest

Removing an Image

To remove an image from your local system:

podman rmi alpine

Networking and Storage with Podman

Podman provides options for managing networking and persistent storage for containers.

Network Management

By default, Podman creates a network for container communication. You can create your own custom network for specific use cases.

Create a Custom Network:

podman network create my_network

Connect a Container to the Custom Network:

podman run -d --name web --network my_network nginx

Volume Management

Podman also offers persistent storage through volumes, which are critical for data integrity when containers are stopped or removed.

Create a Persistent Volume:

podman volume create my_data_volume

Run a Container with Volume:

podman run -d --name db -v my_data_volume:/var/lib/mysql mysql

Security with Podman

Podman is designed with security in mind and offers several features to help ensure secure container operation.

Rootless Operation

One of the key features of Podman is its ability to run containers without requiring root privileges. This significantly reduces security risks, as containers do not have access to the system’s root-level resources.

SELinux Support

Podman is compatible with SELinux (Security-Enhanced Linux), which provides an additional layer of security for containers by enforcing mandatory access control policies.

Signed Container Images

Podman supports signed container images, ensuring that the images you are using are verified and trusted. This feature helps ensure that only authorized container images are used in your environment.


Conclusion

Podman is a powerful alternative to Docker, offering flexible and secure solutions for container management. Its ability to run without a daemon, operate rootless, and maintain compatibility with Docker makes it an attractive choice for developers and system administrators alike. Whether you’re working on a small project or orchestrating complex containerized applications, Podman provides the tools and capabilities to manage containers effectively. For more advanced use cases, be sure to explore the official Podman documentation.

Next Article

Fixing the ‘err_cache_miss’ Error in Chrome

Subscribe to our Newsletter! 📬

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨