[ad_1]
For anybody who’s made the swap 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 may skip on to working together with your containers.
However why would you wish to study a wholly new software? Happily, Podman is sort of a direct 1:1 substitute for Docker, so if one you should use the opposite. I’ve already helped you are 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 knowledge. Every part goes nice till catastrophe strikes. The container fails and takes your knowledge down with it. You don’t need that.
SEE: Hiring kit: Back-end Developer (TechRepublic Premium)
To keep away from such a disaster, you’d deploy these containers utilizing volumes. By doing this, the info is saved to a persistent state, so if the container goes down, the info continues to be secure and can be utilized by a special container. Belief me, you wish to use volumes for any container that may depend upon knowledge. That is particularly so when you or what you are promoting is dependent upon the info utilized by that container.
With that stated, how do you’re employed with volumes in Podman? Let’s discover out.
What you’ll must 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.
Find out how 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 must be easy:
nginx-volume
You may confirm the amount 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 could possibly challenge 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
}
]
Find out how to use a quantity with Podman
Now that we’ve created the amount, 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 net server. Turn into the amount 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>Hiya, TechRepublic!</h2>
Save and shut the file.
Deploy the container hooked up to the amount 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 online browser to http://IP:8080, the place IP is the IP handle of the internet hosting server, we should always see our “Hiya, TechRepublic!” message.
In case you see an error, you’ll must 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 info within the quantity will stay intact. In case you ever must delete the amount, you could possibly merely challenge 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 hold persistent knowledge 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 execs from Jack Wallen.
[ad_2]
Source link