Podman : conteneurs rootless sans daemon

Podman : conteneurs rootless sans daemon

Podman est l'alternative a Docker : meme CLI, pas de daemon root, conteneurs rootless par defaut. Pousse par Red Hat, integre nativement a systemd. Le futur des conteneurs en environnement entreprise.

Introduction

Podman ("Pod Manager") :

  • 100% compatible CLI Docker (alias docker=podman)
  • Pas de daemon : chaque commande tourne en process utilisateur
  • Rootless par defaut : containers tournent sans root
  • Generation d'unites systemd natifs
  • Support des pods (groupe de containers partageant des resources, comme Kubernetes)
  • Format OCI standard

Avantages vs Docker :

  • Securite : pas de socket root expose
  • Pas de single point of failure (daemon)
  • Integration native systemd

Prerequis

  • VPS Linux Debian 12 / Ubuntu 24.04 / Rocky 9
  • Acces root pour installer
  • Un user non-root pour usage rootless

Etape 1 : Installation

Debian / Ubuntu

sudo apt update
sudo apt install -y podman
podman --version

Rocky / RHEL

sudo dnf install -y podman

Etape 2 : Premier container (rootless)

En tant qu'utilisateur normal (pas root) :

podman run -d -p 8080:80 --name web nginx

Verifiez :

podman ps
curl http://localhost:8080

Le container tourne sous votre user. Pas de daemon, pas de root.

Etape 3 : Commandes Docker-compatibles

podman ps             # lister
podman images         # images locales
podman pull alpine    # download image
podman exec -it web bash
podman logs web
podman stop web
podman rm web
podman rmi nginx
podman inspect web

Tout pareil que Docker.

Etape 4 : Alias docker = podman

Pour une transition transparente :

sudo apt install -y podman-docker

/usr/bin/docker est cree comme symlink vers podman. Vos scripts existants fonctionnent.

Etape 5 : Build une image

Dockerfile (renommez en Containerfile si vous voulez, podman comprend les deux) :

FROM alpine:3.18
RUN apk add --no-cache nginx
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Build :

podman build -t monweb:1.0 .

Run :

podman run -d -p 8080:80 monweb:1.0

Etape 6 : Generer un service systemd

Au lieu d'utiliser un daemon pour redemarrer les containers au boot, Podman genere directement un service systemd :

podman create --name monapp -p 8080:80 nginx
podman generate systemd --new --files --name monapp

Cela genere ~/container-monapp.service. Installez-le :

mkdir -p ~/.config/systemd/user
mv container-monapp.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now container-monapp

Verifiez :

systemctl --user status container-monapp

Pour que le service tourne meme apres logout :

loginctl enable-linger $USER

Etape 7 : Quadlet (mode moderne)

Depuis Podman 4.4+, Quadlet simplifie la creation d'unites systemd. Creez ~/.config/containers/systemd/monapp.container :

[Unit]
Description=Mon app Nginx
After=network-online.target

[Container]
Image=docker.io/library/nginx:alpine
PublishPort=8080:80
ContainerName=monapp

[Service]
Restart=on-failure

[Install]
WantedBy=multi-user.target default.target
systemctl --user daemon-reload
systemctl --user start monapp

Quadlet genere le service systemd a la volee.

Etape 8 : Pods (groupes de containers)

Un pod Podman = plusieurs containers partageant network + storage, comme Kubernetes :

podman pod create --name webpod -p 8080:80

podman run -d --pod webpod --name nginx nginx
podman run -d --pod webpod --name redis redis

nginx et redis partagent le meme localhost. nginx peut joindre redis sur localhost:6379.

Etape 9 : podman-compose

Pour compatibilite docker-compose.yml :

sudo apt install -y podman-compose
podman-compose up -d
podman-compose ps
podman-compose down

Lit docker-compose.yml et le traduit en commands podman.

Etape 10 : Securite : SELinux / AppArmor

Podman s'integre nativement a SELinux. Si SELinux est enforce, vous devez ajouter :Z aux volumes pour le bon labeling :

podman run -d -v /home/user/data:/data:Z nginx

Sans :Z, le container ne pourra pas lire le volume.

Etape 11 : Networking

podman network create monreseau
podman run -d --network=monreseau --name web nginx
podman run -d --network=monreseau --name app monapp:1.0

app peut joindre web via DNS interne :

podman exec app curl http://web

Etape 12 : Export / Import vers Kubernetes

Generez un YAML Kubernetes depuis vos containers Podman :

podman generate kube monapp > monapp-k8s.yaml

Vous pouvez ensuite deployer directement sur K8s :

kubectl apply -f monapp-k8s.yaml

Et l'inverse :

podman play kube monapp-k8s.yaml

Podman lance les containers comme decrit dans le YAML K8s. Tres utile pour developper localement sans installer K8s.

Depannage

"newuidmap: write to uid_map failed"

Limites rootless mal configurees. Verifiez :

cat /etc/subuid /etc/subgid

Vous devriez avoir une plage allouee a votre user :

votreuser:100000:65536

Sinon :

sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 votreuser
podman system migrate

Port < 1024 en rootless

Rootless n'a pas le droit de bind sur les ports privileges (<1024). Solutions :

  1. Utilisez un port >= 1024 puis reverse-proxy (Nginx, Caddy)
  2. Autorisez votre user :
sudo setcap 'cap_net_bind_service=+ep' /usr/bin/podman
  1. Activez net.ipv4.ip_unprivileged_port_start=80 :
echo "net.ipv4.ip_unprivileged_port_start=80" | sudo tee /etc/sysctl.d/99-podman.conf
sudo sysctl --system

"Error: error preparing container"

Generalement un probleme de SELinux ou permissions. Verifiez :

podman info
podman events

Image qui ne se telecharge pas

Configurez les registries dans ~/.config/containers/registries.conf :

[[registry]]
location = "docker.io"

Commandes utiles

# Run / manage
podman run -d -p 8080:80 nginx
podman ps -a
podman stop monapp
podman rm monapp
podman exec -it monapp sh

# Images
podman pull alpine
podman build -t monapp:1.0 .
podman tag monapp:1.0 registry/monapp:1.0
podman push registry/monapp:1.0
podman images

# System
podman system info
podman system prune -a   # nettoyer
podman version

# Pods
podman pod ps
podman pod create --name webpod -p 8080:80
podman pod start webpod

# Generate systemd (legacy)
podman generate systemd --new --files --name monapp

# Generate Kubernetes YAML
podman generate kube monapp > k8s.yaml
podman play kube k8s.yaml

Conclusion

Podman remplace Docker avec quelques avantages :

  • Pas de daemon = pas de SPOF
  • Rootless = securite accrue
  • Integration systemd native
  • Compatible Kubernetes YAML

Pour aller plus loin :

  • Migrez votre stack docker-compose avec podman-compose ou Quadlet
  • Combinez avec Buildah pour build sans daemon
  • Explorez Podman Desktop (GUI cross-platform)

Ressources

Join our Discord community server

For any questions, suggestions, or just to chat with the community, join us on Discord!

900+Members