Podman is a container management tool that provides similar functionality to Docker but is designed to be daemonless and rootless. This means you don’t need a long-running background service (daemon) to manage your containers, and you don’t need root privileges for most operations.
In this article, we will cover how to install and use Podman on Ubuntu 22.04 & 20.04 LTS systems.
Installing Podman on Ubuntu
1. Update the System:
Before you begin, ensure that your system package database is up-to-date:
sudo apt update && sudo apt upgrade -y
2. Install Podman:
Podman is available in the default Ubuntu repositories, so installing it is straightforward:
sudo apt install -y podman
3. Verify the Installation:
To ensure Podman has been installed correctly:
You should see the version of Podman printed to the console.
Basic Usage of Podman
1. Running Containers:
The syntax for running a container with Podman is very similar to Docker:
podman run -it hello-world
This will download the hello-world docker image (if not already present) and launch a new container. On successful run, you will see the following result:
2. Listing Containers:
To list running containers:
To list all containers (including stopped ones):
podman ps -a
3. Removing Containers:
To remove a container:
podman rm <container_id>
4. Handling Images:
List all available images on your system:
Remove an image:
podman rmi <image_id>
5. Podman Pods:
Podman has a concept called “pods”. A pod is a group of one or more containers that share the same network namespace. This is similar to Kubernetes pods. To create a new pod:
podman pod create --name mypod
Run a container within the pod:
podman run --pod mypod -d <image>
6. Rootless Containers:
One of Podman’s main features is the ability to run rootless containers. This means you can run containers as a non-root user, without any special permissions. Simply run the podman command as your regular user.
7. Using Volumes:
You can mount volumes (directories or files from the host) into your containers. For example:
podman run -v /path/on/host:/path/in/container -it /bin/bash
Tips for Transitioning from Docker to Podman
If you’re transitioning from Docker, you might find these tips helpful:
- Command Aliasing: The Podman command-line interface (CLI) is designed to be compatible with Docker’s CLI. You can alias docker to podman to use familiar commands:
- Podman Compose: If you use docker-compose, you’ll want to check out podman-compose, a script to help Podman users setup and manage pods and containers.
- Networking and Storage: While Podman handles networking and storage differently than Docker, it offers a variety of configurations. Dive into the documentation to understand the differences.
Podman provides a compelling alternative to Docker, especially for users who prioritize security, as it can run without root privileges. With the ability to manage containers effectively, without a daemon, and with a similar CLI, the transition to Podman can be quite smooth.