Rootless mode allows you to run containers without root privileges, providing better security and user isolation.
- Root or sudo access (for initial setup)
- Linux system with systemd
Create a dedicated non-root user for running containers:
# Check current user (should be root or have sudo access)
whoami
# Create new user (using 'staging' as example)
sudo adduser staging
sudo usermod -aG sudo staging
# Configure subordinate UIDs and GIDs for user namespace mapping
sudo usermod --add-subuids 100000-165535 staging
sudo usermod --add-subgids 100000-165535 stagingsudo apt-get update
sudo apt-get install -y podman uidmap slirp4netns fuse-overlayfs golangSwitch to the non-root user and configure container registries:
# Switch to new user
su - staging
# Verify you're non-root
whoami
id
# Configure container registries
mkdir -p ~/.config/containers
cat > ~/.config/containers/registries.conf << 'EOF'
unqualified-search-registries = ["docker.io"]
EOF# Test rootless Podman
podman run hello-world
# Verify rootless mode is enabled
podman info | grep rootless
# Should output: rootless: trueLingering allows the user to run systemd services even when not logged in, preventing containers from stopping on logout:
# Exit to root/sudo user
exit
# Enable lingering (use username or UID)
sudo loginctl enable-linger staging
# Verify lingering is enabled
loginctl show-user staging | grep Linger
# Should output: Linger=yes
# Switch back to user
su - staging# Build from Dockerfile in current directory
podman build -t app:1.0.0 .
# Run with port mapping
podman run \
--rm \
--uidmap "+100000:0:1" \
--gidmap "+100000:0:1" \
-p 8080:8080 \
--name myapp \
-d \
app:1.0.0