Getting Started with Podman: A Modern Alternative to Docker
Podman is an innovative container management tool that offers a range of advantages over traditional container solutions like Docker. Developed by Red Hat, Podman is designed to be a daemonless container engine, which means it can run containers without requiring a background service. This architecture enhances security and simplifies the management of containers, making it an attractive choice for developers and system administrators alike.
One of the key benefits of Podman is its compatibility with Docker commands, allowing users to transition smoothly from Docker to Podman without a steep learning curve. Additionally, Podman supports rootless containers, which provide an extra layer of security by allowing users to run containers without elevated privileges. This feature is particularly valuable in multi-user environments.
In this guide, we will explore the essential commands for pulling images, creating containers, managing them, and accessing their shell. For our examples, we will focus on the popular Alpine and Ubuntu images, showcasing how easy it is to get started with Podman.
1. Installation
Before you begin, ensure that Podman is installed on your system. You can install it using your package manager. For example, on a Debian-based system, run:
sudo apt update
sudo apt install podman
2. Pulling Images
Pull Alpine Linux Image
To pull the Alpine Linux image, use:
podman pull alpine
Pull Ubuntu Image
To pull the Ubuntu image, use:
podman pull ubuntu
3. Listing Available Images
To see all images available on your local system, run:
podman images
4. Searching for Images on Docker Hub
To search for images on Docker Hub, use:
podman search docker.io/
For example, to search for Alpine images on Docker Hub:
podman search docker.io/alpine
5. Creating Containers
Create a Container from Alpine Image
To create a container from the Alpine image, use:
podman create --name my-alpine-container alpine
Create a Container from Ubuntu Image
To create a container from the Ubuntu image, use:
podman create --name my-ubuntu-container ubuntu
6. Listing Containers
To see all containers (running and stopped), use:
podman ps -a
To see only running containers, use:
podman ps
7. Starting and Stopping Containers
Start a Container
To start a container, use:
podman start my-alpine-container
Stop a Container
To stop a running container, use:
podman stop my-alpine-container
8. Accessing a Container's Shell
To access the shell of a running container, use the exec command:
For Alpine
podman exec -it my-alpine-container /bin/sh
For Ubuntu
podman exec -it my-ubuntu-container /bin/bash
9. Creating and Running Containers
Using podman run
Instead of creating a container and then starting it, you can use the podman run
command to create and start a container in one step. This is
particularly useful for containers that need to run a long-lived
process.
For example, to create and run an Alpine container interactively, use:
podman run -it --name my-alpine-container alpine /bin/sh
This command will start the container and give you access to its shell immediately.
10. Deleting Containers and Images
Delete a Container
To delete a stopped container, use:
podman rm my-alpine-container
Delete an Image
To delete an image, use:
podman rmi alpine
Conclusion
This guide provides a basic overview of using Podman for container management. With these commands, you can efficiently pull images, create and manage containers, and access their shells.
PS Note: Avoiding Container Exit Issues
When using podman create
, be aware that the container will not start running until you explicitly start it with podman start
.
If the container is created without a long-running command, it may exit
immediately after starting, which can lead to confusion when trying to
access its shell. To avoid this issue, consider using podman run
to create and start the container in one step, or ensure that the command you use keeps the container alive.
Happy containerizing!
Join the conversation