Introduction
Podman is a container management tool that provides similar functionality to Docker but is designed to be daemon-free and root-free. This means you don't need a long-running background service (daemon) to manage 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 and 20.04 LTS systems.
Installing Podman on Ubuntu
Update the system
Before you begin, make sure your system package database is up to date:
sudo apt update && sudo apt upgrade -y
Install Podman:
Podman is available in the default Ubuntu repositories, so installing it is simple:
sudo apt install -y podman
Check the installation:
To ensure that Podman has been installed correctly:
podman --version
You should see the Podman version printed on your console.
Basic usage of Podman
Running containers:
The syntax for running a container with Podman is very similar to Docker:
podman run -it hello-world
The Hello-World docker image will be downloaded (if not already present) and a new container will be launched.
List of containers:
To list running containers:
podman ps
To list all containers (including stopped ones):
podman ps -a
Removing Containers:
To remove a container:
podman rm <container_id>
Image management:
List all images available on your system:
podman images
Remove an image:
podman rmi <image_id>
Pod Podman:
Podman has a concept called “pod”. 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 inside the pod:
podman run --pod mypod -d <image>
Rootless containers
One of the key features of Podman is the ability to run containers without root. This means you can run containers as a non-root user, without special permissions. Simply run the podman command as a normal user.
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 switching from Docker, you may find these tips helpful:
- Command aliasing: The Podman command line interface (CLI) is designed to be compatible with the Docker CLI. You can create docker alias on podman to use familiar commands:
alias docker=podman
- Podman Compose: If you use docker-compose, you'll want to take a look at podman-compose, a script to help Podman users set up and manage pods and containers.
- Networking and storage: Although Podman handles networking and storage differently than Docker, it offers a variety of configurations. Dive into the documentation to understand the differences.
Conclusion
Podman provides an attractive 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.