For anybody who’s made the change from a Ubuntu-based to an RHEL-based Linux distribution for container deployments, you’ve in all probability realized that Docker isn’t the simplest or best choice in your new platform. Fortunately, Podman is put in by default on most RHEL-based distributions, so you’ll be able to skip on to working along with your containers.
However why would you need to be taught a wholly new software? Thankfully, Podman is nearly a direct 1:1 substitute for Docker, so if you already know one you should use the opposite. I’ve already helped you’re taking your first steps with Podman and this time round we’re going to increase {that a} bit by creating and managing volumes.
Why are volumes vital? Easy — persistent storage. Say, for instance, you deploy a container that makes use of information. Every little thing goes nice till catastrophe strikes. The container fails and takes your information down with it. You don’t need that.
SEE: Hiring package: Again-end Developer (TechRepublic Premium)
To keep away from such a disaster, you’d deploy these containers utilizing volumes. By doing this, the information is saved to a persistent state, so if the container goes down, the information continues to be protected and can be utilized by a unique container. Belief me, you need to use volumes for any container that can rely upon information. That is particularly so when you or your corporation is dependent upon the information utilized by that container.
With that stated, how do you’re employed with volumes in Podman? Let’s discover out.
What you’ll have to create and handle volumes with Podman
The one factor you’ll want for it is a Linux distribution with Podman put in. This might be RHEL, Rocky Linux, AlmaLinux, or CentOS. That’s it.
The best way to create a quantity with Podman
The very first thing we have to do is create a quantity. Log in to your Linux distribution and open a terminal window. Let’s say we’re going to create a quantity for an NGINX container. Create that quantity with:
podman quantity create nginx-volume
The output needs to be easy:
nginx-volume
You possibly can confirm the quantity creation with the command:
podman quantity ls
The above command ought to print out one thing like this:
DRIVER VOLUME NAME
native nginx-volume
To get extra info, you may situation the command:
podman quantity examine nginx-volume
The above command will print out one thing 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
}
]
The best way to use a quantity with Podman
Now that we’ve created the quantity, let’s use it with an NGINX container deployment. Earlier than we do, let’s have some enjoyable and create a brand new index.html file for the NGINX internet server. Develop into the quantity listing with the command:
cd /residence/$USER/.native/share/containers/storage/volumes/nginx-volume/_data
Now, let’s create our index.html with:
nano index.html
In that file, paste the next:
<h2>Hi there, TechRepublic!</h2>
Save and shut the file.
Deploy the container hooked up to the quantity with the command:
podman run -d -p 8080:80 -v nginx-volume:/usr/share/nginx/html --name nginx-volumetest nginx:newest
What we’ve accomplished with the above command is mapped our nginx-volume to the /usr/share/nginx/html listing throughout the NGINX container. Now, if we level an internet browser to http://IP:8080, the place IP is the IP tackle of the internet hosting server, we should always see our “Hi there, TechRepublic!” message.
When you see an error, you’ll have to open the firewall with the next two instructions:
sudo firewall-cmd --permanent --add-port 8080/tcp
sudo firewall-cmd --reload
Now, when you reload the net web page, you’ll see the message (Determine A).
Determine A
Now, ought to your container fail, the information within the quantity will stay intact. When you ever have to delete the quantity, you may merely situation the command:
podman quantity rm nginx-volume
And that’s all there may be to managing volumes with Podman. This can be a essential characteristic for anybody seeking to preserve persistent information for his or her container deployments.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the most recent tech recommendation for enterprise professionals from Jack Wallen.