Skip to main content

Basics

Essential Podman commands, installation guide, and fundamental container operations for getting started with daemonless container management.

Installation

Linux Systems

RHEL/CentOS/Fedora

# Fedora
sudo dnf install podman

# RHEL/CentOS 8+
sudo dnf install podman

# RHEL/CentOS 7
sudo yum install podman

# Enable user namespaces (if needed)
echo 'user.max_user_namespaces=28633' | sudo tee -a /etc/sysctl.d/userns.conf
sudo sysctl -p /etc/sysctl.d/userns.conf

Ubuntu/Debian

# Ubuntu 20.04+
sudo apt update
sudo apt install podman

# Ubuntu 18.04 (via PPA)
sudo add-apt-repository -y ppa:projectatomic/ppa
sudo apt update
sudo apt install podman

# Debian
echo 'deb http://deb.debian.org/debian buster-backports main' | sudo tee /etc/apt/sources.list.d/backports.list
sudo apt update
sudo apt install -t buster-backports podman

Arch Linux

sudo pacman -S podman

macOS

# Install via Homebrew
brew install podman

# Initialize and start Podman machine
podman machine init
podman machine start

# Verify installation
podman info

Windows

# Install via Chocolatey
choco install podman

# Or download from GitHub releases
# https://github.com/containers/podman/releases

Basic Configuration

Initial Setup

# Check installation
podman version
podman info

# Configure registries
sudo mkdir -p /etc/containers
sudo tee /etc/containers/registries.conf <<EOF
[registries.search]
registries = ['docker.io', 'quay.io', 'registry.fedoraproject.org']

[registries.insecure]
registries = []

[registries.block]
registries = []
EOF

# Configure storage (optional)
mkdir -p ~/.config/containers
tee ~/.config/containers/storage.conf <<EOF
[storage]
driver = "overlay"
runroot = "/run/user/1000/containers"
graphroot = "/home/user/.local/share/containers/storage"
EOF

User Configuration

# Enable user lingering (systemd)
sudo loginctl enable-linger $USER

# Configure subuid/subgid for rootless containers
grep $USER /etc/subuid /etc/subgid

# If not present, add entries
echo "$USER:100000:65536" | sudo tee -a /etc/subuid
echo "$USER:100000:65536" | sudo tee -a /etc/subgid

# Restart user session or reboot

Essential Commands

Container Lifecycle

# Run container (foreground)
podman run alpine echo "Hello World"

# Run container (background/detached)
podman run -d nginx

# Run interactive container
podman run -it alpine sh
podman run -it ubuntu bash

# Run with specific name
podman run --name mycontainer -d nginx

# Run with port mapping
podman run -p 8080:80 -d nginx

# Run with environment variables
podman run -e ENV_VAR=value alpine env

# Run with volume mount
podman run -v /host/path:/container/path alpine ls /container/path

# Run with working directory
podman run -w /app alpine pwd

Container Management

# List containers
podman ps # Running containers
podman ps -a # All containers
podman ps -q # Only container IDs
podman ps --format table # Formatted output

# Start/stop containers
podman start container_name
podman stop container_name
podman restart container_name
podman pause container_name
podman unpause container_name

# Remove containers
podman rm container_name
podman rm -f container_name # Force remove running container
podman rm $(podman ps -aq) # Remove all containers

# Container inspection
podman inspect container_name
podman logs container_name
podman logs -f container_name # Follow logs
podman top container_name # Running processes
podman stats container_name # Resource usage

Image Management

# List images
podman images
podman images -a # Include intermediate images
podman images --format table

# Pull images
podman pull alpine
podman pull alpine:3.18
podman pull docker.io/library/ubuntu:20.04

# Remove images
podman rmi image_name
podman rmi -f image_name # Force remove
podman image prune # Remove unused images
podman image prune -a # Remove all unused images

# Image inspection
podman inspect image_name
podman history image_name # Image layers

System Information

# System information
podman info
podman version
podman system df # Storage usage
podman system events # Real-time events

# System cleanup
podman system prune # Remove unused data
podman system prune -a # Remove all unused data
podman system prune --volumes # Include volumes

# Reset system
podman system reset # Remove all containers, images, etc.

Working with Containers

Executing Commands

# Execute command in running container
podman exec container_name ls
podman exec -it container_name bash
podman exec -u root container_name id

# Execute with environment variables
podman exec -e VAR=value container_name env

# Execute with working directory
podman exec -w /app container_name pwd

File Operations

# Copy files to/from container
podman cp file.txt container_name:/path/
podman cp container_name:/path/file.txt ./

# Create tar archive of container files
podman export container_name > container.tar

# Import tar archive as image
podman import container.tar new_image_name

Container Commit

# Create image from container
podman commit container_name new_image_name

# Commit with metadata
podman commit -m "Added custom config" \
-a "Author Name" \
container_name \
new_image_name:v1.0

Docker Compatibility

Command Aliases

# Create Docker aliases
alias docker=podman
alias docker-compose=podman-compose

# Add to shell profile
echo 'alias docker=podman' >> ~/.bashrc
echo 'alias docker-compose=podman-compose' >> ~/.bashrc

Socket Compatibility

# Start Podman API service
podman system service --time=0 unix:///tmp/podman.sock &

# Use with Docker clients
export DOCKER_HOST=unix:///tmp/podman.sock
docker ps # Uses Podman backend

# Systemd socket activation
systemctl --user enable podman.socket
systemctl --user start podman.socket
export DOCKER_HOST=unix:///run/user/$UID/podman/podman.sock

Environment Variables

# Common Docker environment variables
export CONTAINER_HOST=unix:///run/user/$UID/podman/podman.sock
export CONTAINER_SSHKEY=/path/to/ssh/key
export CONTAINER_CONNECTION=podman-machine-default

Common Patterns

Development Workflow

# Quick development container
podman run -it --rm \
-v $(pwd):/workspace \
-w /workspace \
node:18-alpine \
sh

# Web development with port forwarding
podman run -it --rm \
-p 3000:3000 \
-v $(pwd):/app \
-w /app \
node:18-alpine \
npm start

Production Patterns

# Run with resource limits
podman run -d \
--memory=512m \
--cpus=1.0 \
--restart=always \
nginx

# Run with health check
podman run -d \
--health-cmd="curl -f http://localhost || exit 1" \
--health-interval=30s \
--health-timeout=10s \
--health-retries=3 \
nginx

Cleanup Routines

# Daily cleanup script
#!/bin/bash
podman container prune -f
podman image prune -f
podman volume prune -f
podman network prune -f

# Weekly deep cleanup
podman system prune -a -f --volumes

Configuration Files

Container Configuration

# View container config
podman inspect container_name | jq .Config

# Export container config
podman inspect container_name > container_config.json

Runtime Configuration

# User containers.conf
~/.config/containers/containers.conf

# System containers.conf
/etc/containers/containers.conf

# Example configuration
[containers]
default_capabilities = [
"CHOWN",
"DAC_OVERRIDE",
"FOWNER",
"FSETID",
"KILL",
"NET_BIND_SERVICE",
"SETFCAP",
"SETGID",
"SETUID",
"SYS_CHROOT"
]

[engine]
events_logger = "journald"
runtime = "crun"

Quick Reference

Most Used Commands

# Container operations
podman run -it alpine sh
podman ps
podman stop container_name
podman rm container_name

# Image operations
podman pull image_name
podman images
podman rmi image_name

# System operations
podman info
podman system prune

Useful Flags

  • -d, --detach: Run in background
  • -it: Interactive with TTY
  • -p, --publish: Publish ports
  • -v, --volume: Mount volumes
  • -e, --env: Set environment variables
  • --name: Set container name
  • --rm: Remove container on exit
  • -u, --user: Set user/UID