Signup/Sign In
LAST UPDATED: JULY 25, 2023

Guide to Podman: A daemonless alternative to Docker!

    You may be already familiar Docker, a powerful tool used to manage containers and pods. It uses a client-server architecture, where the Docker daemon keep running in the background to handle container operations.

    In this article, you will learn about Podman, a daemonless alternative to docker. If you are already familiar with Docker, then there won't be a big learning curve for Podman.

    Podman v/s Docker

    Since Docker runs as a Daemon and its client-server architecture, a user requires root privileges to run Docker. It also introduces potential security risks.

    But Podman, on the other hand, does not use a daemon. But instead runs as a normal process that forks and execs containers. This means, Podman does not require root privileges to run containers, and it does not consume system resources when no container is running.

    Podman v/s Docker Architecture

    Podman also provide similar features as Docker. It is part of the libpod library, which provides APIs for other tools to interact with containers. It is compatible with the Open Container Initiative (OCI) standards and can run OCI images. Not only that, but it also supports the Docker API, so you can use it as a drop-in replacement for Docker.

    Now, if you are convinced to use Podman and find it suitable for your purpose. Let's move to the installation of Podman on different platforms.

    Podman Installation

    Podman is available for various Linux distros, as well as Windows and Mac. Depending on your OS, you may need to install some dependencies or enable some features before installing Podman.

    Here are some instructions for Podman installation on different platforms:

    Install Podman in MacOS

    Podman can be easily installed using Homebrew package manager in mac. Use the below command:

    brew install podman

    For Mac, You will also need to create and start a Podman machine, which is a QEMU-based virtual machine that runs the Podman service.

    podman machine init
    podman machine start

    You can use the podman machine command to manage your Podman machines.

    Install Podman in Windows

    On Windows, Podman works after you enable the Windows Subsystem for Linux (WSL) feature and install a Linux distribution that supports Podman, such as Ubuntu or Fedora.

    1. Install Podman

    Download and install using Podman Windows Installer. (podmain-v4.x.x.msi)

    Also, You can either use Winget or Choco package manager.

    winget install podman
    choco install podman # run with powershell administrator

    Install podman in Windows with choco and winget

    1. Start Podman Machine

    Open PowerShell, and run the below command to start Podman machine:

    podman machine init

    If WSL is not installed already. This will automatically install WSL and other required components and restart the PC.

    Install Podman on Linux

    You can directly install Podman using your distribution's package manager. Some common commands are:

    # Arch Linux & Manjaro Linux
    sudo pacman -S podman
    
    # Alpine Linux
    sudo apk add podman
    
    # CentOS
    sudo yum -y install podman
    
    # Debian
    sudo apt -y install podman
    
    # Fedora
    sudo dnf -y install podman
    
    # Ubuntu 20.10 or newer
    sudo apt -y update
    sudo apt -y install podman

    These commands should run on most of Linux Distros based on the distros mentioned above.

    If, for some reason, Podman is not installed with the above commands. You can always directly download the packages from official releases and install them manually.

    Verify Podman installation

    To verify that Podman is installed correctly, you can run:

    podman --version


    podman version x.y.z

    where x.y.z is the version number of Podman.

    How to Use Podman?

    If you are already familiar with Docker command line tool, then using Podman CLI is no big deal. All its commands and options are exactly the same as Docker's.

    Pro-tip: Make “docker” alias for “podman” in command line and use Podman like you would use Docker:

    alias docker=podman

    Here are some basic podman commands:

    Command Description
    podman stop Stops, a container, or pod
    podman restart Restarts a container or pod
    podman rm Removes a container or pod
    podman inspect Inspects a container or pod
    podman logs Views the logs of a container or pod
    podman attach Attaches to a running container or pod
    podman exec Executes a command inside a running container / pod

    Let's explore more useful Podman command.

    Search, Pull, and List Images with Podman

    You can search for images on remote registries with Podman. For example, to search for official httpd images on Docker Hub run:

    podman search httpd --filter=is-official

    You should see a list of images related to the term httpd.

    To download (pull) an image from the registry, you can use the podman pull command with the image name. For example, to pull the latest httpd image from Docker Hub run:

    podman pull docker.io/library/httpd:latest

    You can optionally specify a tag or a digest to pull a specific version of the image.

    To list the images that you have pulled or built locally, you can use the podman images command. For example:

    podman images

    You should get output something like this:


    REPOSITORY TAG IMAGE ID CREATED SIZE
    docker.io/library/httpd latest d294bb32c207 12 hours ago 148 MB

    Create and Run Containers

    Podman can create and run containers, an isolated process that runs an application, and pods, group of containers that share resources and lifecycle, from images.

    To create a container from an image, you can use the podman create command with the image name and any options or arguments that you want to pass to the container.

    For example, you can create a container named web from the httpd image and expose port 80 using:

    podman create --name web -p 8080:80 docker.io/library/httpd:latest


    a0f8f9f0c8a1c4a0a9b3b3e4f7f8c1d6c2d7a0b9d9b5c4a0a9b3l3e4f7f8c1d6

    This is the container ID, which is actually a unique identifier for the container. You can use the container ID or the container name to refer to this container in any Podman command.

    To start a container that you have created, you can use the podman start command with the container ID or name. For example, to start the web container, you can run:

    podman start web

    You should get “web” as output.

    Which means the container has started successfully. You can verify that the container is running by using the podman ps command, which lists the running containers. For example:

    podman ps


    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    868abc21a65a docker.io/library/httpd:latest httpd-foreground About a minute ago Up About a minute ago 0.0.0.0:8080->80/tcp web

    You can create and start a container in one step using podman run command instead of podman create and podman start. For example:

    podman run --name web2 -p 8080:80 -d docker.io/library/httpd:latest

    The -d option tells Podman to run the container in detached mode, which means that it runs in the background and does not attach to your terminal.


    b1c2d3e4f5a6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0e1f2

    Create and Run Pods

    To create a pod for an image, you can use the podman pod create command with any options that you want to apply to the container and pod.

    For example, you can create a pod named webpod and expose port 8080 using:

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


    c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0e1f2g3h4

    Similar to we discussed above, you can use the pod ID or the pod name to refer to the pod.

    To create and start a container named web3 from the same image inside the webpod pod, you can run:

    podman run --name web3 --pod webpod -d docker.io/library/httpd:latest

    You can verify that the container is running inside the pod by using the podman ps command with the --pod option. For example:

    podman ps --pod

    You should see something like:


    POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID IMAGE PORTS
    c3d4e526g7h8 webpod Running 1 minutes ago 2 d4e5f7g7h8i9 k8s.gcr.io/pause:3.5 0.0.0.0:8080->80/tcp
    b1c2d3f4f5a6 Running 4 minutes ago 1 b1c2d3e4f5a2 docker.io/library/httpd:latest 0.0.0.0:81->80/tcp
    a0f8f9f1b8a1 Running 7 minutes ago 1 a1f8f9f0b8a2 docker.io/library/httpd:latest 0.0.0.0:80->80/tcp

    As you can see, the web3 container is running inside the webpod pod.

    Conclusion

    So, what should you use, Docker or Podman? Of course, Docker also has some advantages over Podman, such as its longer history, larger community, wider adoption and richer ecosystem. But, if Podman gets your job done, then it is always recommended for better security and less system resources.

    Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS