Podman ****** .. highlight:: bash Introduction ============ `Podman`_ is an `OCI`_ compliant container management tool that offers similar features like Docker for managing containers. One of the best features of podman is its ability to run rootless containers. A rootless container is a concept of running and managing containers without root privileges (Normal user). From a security standpoint, rootless containers add an additional layer of security by not allowing root access even if the container gets compromised by an attacker. You can read about the benefits of rootless containers `here`_ .. Note:: Docker also supports rootless mode with some limitations. You can read about it `in this documentation`_ Podman is also daemonless (unlike docker), meaning it doesn’t have a daemon and interacts directly with the runc (runs containers based on OCI specification). Toward the end of the article, I added the difference between Docker and Podman. Also, let’s say there are two users in Linux. user-a and user-b. The containers created by user-a using podman cannot be modified by user-b and vice versa. Another interesting and advanced feature of podman is running containers in Pods. Similar to Kubernetes pods, you can create multi-container pods locally using Podman. You can export the podman pod as a Kubernetes manifest and use a `Kubernetes`_ pod manifest to deploy and podman pod. .. list-table:: Docker Vs Podman :widths: 10 10 :header-rows: 1 * - Podman - Docker * - Podman is Daemonless - Docker has a daemon (containerd ). The docker CLI interacts with the daemon to manage containers. * - Podman interacts with the Linux kernel directly through runc - Docker daemon owns all the child processes of running containers * - Podman can deploy pods with multiple containers. The same pod manifest can be used in Kubernetes. Also, you can deploy a Kubernetes pod manifest as a Podman pod. - There is no concept of a pod in Docker * - Can run rootless containers without any additional configurations. You can run containers with root or non-privileged users. - Docker rootless mode requires additional configurations. Installation ============ :: # Update your packages sudo apt-get update && sudo apt-get upgrade # Install Podman sudo apt-get install podman From there usage is as normal Usage ===== :: # Create Podman Machine podman machine init # Start Podman podman machine start # Verify Info podman info Similar to docker, most commands are the same :: # Start Container podman start # Stop Container podman stop # View Processes podman ps # Remove Container podman rm Registries ========== We can also grab images from any repository; Github, Docker, Google, Redhat, Kubernates From `Podman Add Registry`_ :: # System-Wide configuration nano /etc/containers/registries.conf # User-Specific configuration nano $HOME/.config/containers/registries.conf # An example would be [[registry]] location=quay.io # Or [[registry]] location="my-registry.tld" username="username" password="password" This allows us to have anything accessible for us to pull.. Permissions =========== Podman permissions seem tricky at first, but let's try to understand them together.. Podman utilises something called `SELinux` which is a kernel addon created by the NSA for high security settings, although we don't need this additional security, it is very good to have considering containers are supposed to be secure by design. If you read into how it works, you will slowly start to understand that podman mimics the systems permissions in a strange way, as everything inside the container needs to be run as root under podmans control, the outside permissions need to allow this Below is a table that somewhat explains this. From `Podman Rootless Volumes`_ .. list-table:: The table below shows four possible rootless/rootful operating modes of Podman :widths: 10 10 10 :header-rows: 1 * - You run podman as.. - With containerised process running as.. - The actual UID visible on the host is… * - root - root - 0 * - root - non-root - The UID of the user running the process inside the container * - non-root - root - Your UID * - non-root - non-root - A non-root UID All rootless containers must be run in the same user namespace. If they are not, some things (like sharing the network namespace from another container) would be impossible. By using the same user namespace, your containers can share resources with each other, without needing to ask for root privileges. It uses this user namespace to mount filesystems, or run a container which accesses more than one user ID (UID) or group ID (GID). This mapping is fine for most situations, except when the container needs to be able to share something with the host, like a volume. But - here’s the important thing: When the container runs, any volumes which are shared with it, will appear inside the user namespace as owned by root/root. Because the mapping will map your UID on the host (e.g. 1000) as root (0) in the container. Examples -------- We have gone through and figured out roughly how to get these permissions working nicely in the container. The examples provided are for single run commands, but include the PUID and PGID :: podman run -d \ --name=nextcloud \ -e PUID=7000 \ -e PGID=7000 \ -e TZ=Europe/London \ -p 443:443 \ -v /home/nextcloud/config:/config \ -v /home/nextcloud/data:/data \ --restart unless-stopped \ lscr.io/linuxserver/nextcloud:latest Here the example is for nextcloud, we've created a user `nextcloud` on the server, the UID are set on the user when created. :: su nextcloud mkdir config mkdir data #Run the podman command here Since the directories are created under the `nextcloud` user, they have control and access.. Podman then hooks onto this in a sense, leverages the users permissions then elevates to root within the container. Referring to the table from before, this user is `non-root`, so podman will be `root`. Command Structure ================= From what I have seen there are different ways to structure a `run` command, however they are all Similar :: podman run -d \ --name= \ -e PUID= \ -e PGID= \ -e \ -p \ -v \ --restart