For anyone who has made the switch from an Ubuntu-based to a RHEL-based Linux distribution for container deployments, you’ve probably realized that Docker isn’t the easiest or best option for your new platform. Fortunately, Podman is installed by default on most RHEL-based distributions, so you can go straight to working with your containers.
But why would you want to learn an entirely new tool? Fortunately, Podman is almost a direct 1:1 replacement for Docker, so if you know one, you can use the other. I already helped you take your first steps with Podman and this time we’re going to expand that a little bit by creating and managing volumes.
Why are volumes important? Simple — permanent storage. For example, suppose you deploy a container that uses data. All goes well until disaster strikes. The container fails and takes your data down. You don’t want that.
TO SEE: Hiring Kit: Back-end Developer (Tech Republic Premium)
To avoid such a catastrophe, you would deploy those containers with volumes. By doing this, the data is stored in a permanent state, so if the container fails, the data is still safe and can be used by another container. Trust me, you want to use volumes for any container that depends on data. This is especially true if you or your company relies on the data used by that container.
That said, how do you work with volumes in Podman? Let’s find out.
What you need to create and manage volumes with Podman
All you need for this is a Linux distribution with Podman installed. This can be RHEL, Rocky Linux, AlmaLinux or CentOS. That is it.
Creating a volume with Podman
The first thing we need to do is create a volume. Log into your Linux distribution and open a terminal window. Let’s say we are going to create a volume for an NGINX container. Create that volume with:
podman volume create nginx-volume
The output should be simple:
nginx-volume
You can verify the volume creation with the command:
podman volume ls
The above command should print something like this:
DRIVER VOLUME NAME
local nginx-volume
For more information you can give the command:
podman volume inspect nginx-volume
The above command will print something like this:
[
{
"Name": "nginx-volume",
"Driver": "local",
"Mountpoint": "/home/jack/.local/share/containers/storage/volumes/nginx-volume/_data",
"CreatedAt": "2022-09-26T12:52:36.125241042-04:00",
"Labels": {},
"Scope": "local",
"Options": {},
"MountCount": 0,
"NeedsCopyUp": true,
"NeedsChown": true
}
]
Using a volume with Podman
Now that we’ve created the volume, let’s use it with an NGINX container deployment. Before we do that, let’s have some fun and create a new index.html file for the NGINX web server. Go to the volume directory with the command:
cd /home/$USER/.local/share/containers/storage/volumes/nginx-volume/_data
Now let’s create our index.html with:
nano index.html
In that file, paste the following:
<h2>Hello, TechRepublic!</h2>
Save and close the file.
Deploy the container attached to the volume with the command:
podman run -d -p 8080:80 -v nginx-volume:/usr/share/nginx/html --name nginx-volumetest nginx:latest
What we did with the above command is mapped our nginx volume to the /usr/share/nginx/html directory in the NGINX container. Now if we refer a web browser to: http://IP:8080, where IP is the IP address of the hosting server, we would say our “Hello, TechRepublic!” message.
If you see an error, open the firewall with the following two commands:
sudo firewall-cmd --permanent --add-port 8080/tcp
sudo firewall-cmd --reload
Now if you reload the web page, you will see the message (Image A).
Image A

If your container now fails, the data in the volume will remain intact. If you ever need to delete the volume, you can simply issue the command:
podman volume rm nginx-volume
And that’s all there is to managing volumes with Podman. This is a critical feature for anyone looking to keep persistent data for their container deployments.
Subscribe to TechRepublic’s How to make technology work on YouTube for all the latest technical advice for business professionals from Jack Wallen.