Beginner Guide to Install and Use Podman on AlmaLinux 9
Podman is a Linux-native tool for deploying applications using Open Container Initiative (OCI) containers and container images. It supports multiple container image formats, including Docker images and OCI container images. Also, Podman supports managing pods, and groups of containers.
Podman is a daemon-less tool, running as a single binary command line without a service. It provides a command line similar to Docker, you can use an alias such as 'alias docker=podman'.
In this guide, we will show you how to install and use Podman as a replacement for Docker Engine on an AlmaLinux 9 server. You will learn how to some basics usage of Podman for managing container applications. By completing this guide, you will have a better grasp of using Podman as container orchestration for your local development.
Prerequisites
To begin with this guide, you must have the following:
- An AlmaLinux 9 server - This example uses a server with the hostname 'AlmaLinux9'.
- A non-root user with sudo/root administrator privileges.
Installing Podman
Podman is a daemon less and open-source container orchestration for rapid development. Podman is Linux native application and provides a command line interface similar to Docker.
With Podman, you can find, run, share, and deploy applications using OCI (Open Containers Initiative) containers and container images.
On AlmaLinux, Podman is available by default on the AppStream repository, you can install it using the DNF package manager.
Run the following dnf command to install Podman on your AlmaLinux server.
sudo dnf install podman
Input y when prompted, then press ENTER.
Because the Podman is a daemon-less, you can just run it without starting any daemon.
Run the following command to check the Podman version and detailed information about your installation.
podman version
Below is an output of the current Podman version during this writing:
In addition, you can also verify details of Podman installation using the following command.
podman info
Running Podman as a non-root User
In this section, you will set up Podman for a non-root user. You will create a new user and ensure that the new non-root user can execute and run containers with Podman.
Run the following command to create a new user called 'alice' and configure the password for it. Input a new password when prompted, then repeat.
sudo useradd -m -s /bin/bash alice
sudo passwd alice
Now, add the new user 'alice' to the group 'wheel'. This allows the new user to execute 'sudo' and become root.
sudo usermod -aG wheel alice
After that, run the following command to enable lingering for the user 'alice'. This allows user 'alice' to run the container process for a long period, even when the user is logged out, the process will still be running.
sudo loginctl enable-linger alice
Next, log in as the new user 'alice' using the command below.
su - alice
Run the 'podman' command below to run a new container with the image 'hello-world'.
podman run hello-world
If successful, you should get an output like this:
Lastly, run the following 'podman' command to verify the list of running and exited containers.
podman ps -a
If the configuration is successful, you should see the container with the base image 'hello-world' with the status 'Exited'.
Finding Container Images
By default, Podman will retrieve container images from multiple image registries, such as Redhat image registry, quay.io, and also DockerHub. You can add more container image registries to the configuration '/etc/containers/registries.conf'.
This example will be using DockerHub as a container registry, so let's get started.
Run the following command to find new container images that contain 'httpd'.
podman search httpd
Below is an output you should receive on your terminal:
You can also limit the output by using the '--limit' option like this.
podman search httpd --limit 3
This will show only the top three container images from each container image registry.
Lastly, you can also use the '--filter' option like this.
podman search httpd --filter=is-official
This will show you only official container images.
Downloading Images
After you find the container images, the next step is to download the container images from registries.
Run the following command to download the image 'httpd' with the tag 'alpine'.
podman pull httpd:alpine
Select the image registry that you want to use. This example will be using DockerHub.
After the source is selected, the download process will begin.
Once finished, run the following command to check available images on your AlmaLinux server.
podman images
At this point, if successful, you should get two container images, the image 'hello-world' from quay.io and 'httpd' from the DockerHub.
Inspecting Images
Inspecting images is a powerful to get detailed information on how the container will start. On Podman and Docker, you can inspect images with the option 'inspect'.
Run the following command to get detailed information about the image 'httpd:alpine'.
podman inspect docker.io/library/httpd:alpine
This will show you detailed information about the images, such as the date created, size, default working directory, start command, exposed port, and many more.
You can also specify which part you want to check using the additional parameter like this.
podman inspect --format "size: {{.Size}}" docker.io/library/httpd:alpine
podman inspect --format "ports: {{.Config.ExposedPorts}}" docker.io/library/httpd:alpine
podman inspect --format "workdir: {{.Config.WorkingDir}}" docker.io/library/httpd:alpine
This will show you the size of the image, the default exposed port, and the default working directory.
Running Container
In this section, you will learn how to run the container with Podman.
Enter the following command to run a new container called 'httpd', expose the port 8080 on the host machine, and use the image 'httpd:alpine'. Also, the parameter '--rm', will automatically remove the container upon stopping the container.
podman run -it --rm -d -p 8080:80 --name httpd docker.io/library/httpd:alpine
If successful, you should get the random string and number of the new container id.
Check the running container using the following command. You should get the container 'httpd' with the status 'Up' and use port 8080 on the host machine.
podman ps
Next, you can check the container 'httpd' using the curl command below. Be sure to replace the IP address in the below example with your server IP address.
curl http://192.168.5.20:8080/
If successful, you should get an output like this:
Moreover, you can also access the 'httpd' container via the web browser. Open your web browser and visit the server IP addresses followed by the container port 8080 (i.e: http://192.168.5.20:8080/).
If successful, you should get the default index.html page from the container 'httpd' like this:
Checking Logs Container
With the container 'httpd' up and running, now you will be checking the logs from the container. Knowing this is useful for debugging your applications.
To show all logs from the container 'httpd', run the following command.
podman logs httpd
This is an example of logs from the container 'httpd'.
Next, you can reduce the log output using the '--tail' parameter like this.
podman logs --tail 20 httpd
In this example, the parameter 'tail 20' will show you the latest 20 lines of logs from container 'httpd'.
Stopping Container
Now, if you want to stop the container, simply run the `podman stop`.
Run the following command to stop the container 'httpd'.
podman stop httpd
Once the container 'httpd' stopped, run the command below to check the list of available containers on your system.
podman ps
podman ps -a
The container 'httpd' is automatically deleted after the container is stopped. This is because you run the container with the parameter '--rm'.
Running Container with Custom Volume
In this example, you will run a new container with custom volume. This will mount the local directory on the host machine to the container.
Create a new 'data' directory within the user alice home directory. Then create a new 'index.html file inside the 'data' directory using the nano editor.
mkdir -p ~/data/
nano ~/data/index.html
Insert the following HTML script.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to Container Nginx</title>
</head>
<body>
<h2>Hello from httpd container - Managed with Podman</h2>
</body>
</html>
Save and close the file.
Now, execute the following command to run a new container 'httpd' with the custom volume of the 'data' directory, which will be mounted to the '/usr/local/apache2/htdocs' directory on the container.
podman run --privileged=true -it --rm -d -p 8080:80 --name httpd -v ~/data:/usr/local/apache2/htdocs docker.io/library/httpd:alpine
In addition, this container is running with an additional parameter '--privileged=true'. This is for testing, and yet still the container will be run as a user 'alice' and not the root user. Get more information about privileged flags on Podman.
Next, run the following command to check the running container on your system.
podman ps
If successful, you should see the new container 'httpd' with the status 'Up' and exposed port 8080 on the host machine.
Run the curl command below to verify the new container 'httpd'.
curl http://192.168.5.21:8080/
You should get an output of the index.html script that you created earlier.
As from the web browser on http://192.168.5.21:8080/, you should be displayed the custom page like this:
Logging In to Container
With the 'httpd' container running, you can access the container via shell by utilizing the 'podman exec' command.
Log in to the container 'httpd' using the following command. This will execute the '/bin/sh' shell on the container 'httpd' and attached it to your current session.
podman exec -it httpd /bin/sh
Once logged in, you should be in the directory 'WorkingDir'. In his example, the default WorkingDir is the '/usr/local/apache2' directory.
Now run the following command on the container 'httpd'. Check the current user, the local IP address of the container, and the default gateway for the container.
id
ip a
route -n
You may have an output with a different IP address and gateway, but should be similar to this:
Running and Managing Pod
In Podman, you can create and run Pod. The pod is a wrapper for containers, which means multiple containers can run on a single Pod. As in Kubernetes, Pod is the smallest entity where your application is running.
With Podman, you can create and run Pod, even without Kubernetes.
Run the following command to create a new pod httpdTest with the image 'httpd:alpine' and expose port 9090 on the host machine.
podman run -dt --pod new:httpdTest -p 9090:80 docker.io/library/httpd:alpine
If successful, you should get the random string and number of Pod id.
Now run the following command to check the running Pod on your system.
podman pod ls
You should see the Pod 'httpdTest' with the status 'Running' and 2 containers.
You can now utilize the 'inspect' option on the pod like this.
podman pod inspect httpdTest
You should get detailed information about the pod httpdTest.
You can also check the number of containers that run within the pods including the names of containers using the following command.
podman pod inspect --format="containers: {{.NumContainers}}" httpdTest
podman pod inspect --format "{{.Containers}}" httpdTest
You will get an output like this:
Lastly, run the following command to access the pod httpdTest, which is running on port 9090 on the host machine. If successful, you should get the default index.html page containers that run on pod httpdTest.
curl http://192.168.5.21:9090/
Conclusion
Congratulation! You have now installed Podman on AlmaLinux 9. You have also learned the basic usage of Podman for managing images and containers. Furthermore, you have also learned how to create and run Pod with Podman.