Introduction & Overview
Running a Basic Container
Finding and Managing Container Images
Performing Advanced Container Management
Attaching Persistent Storage to a Container
Managing Containers as Services
Review & Lab Session
This course covers a range of techniques to help you run your own containerized applications using Red Hat. Throughout this course, you will follow along with guided presentations from the Red Hat platform to get a first-hand understanding of how to run containers and manage your workflows using Red Hat.
- Learn the basics of setting up web servers and containers
- Understand how to find and manage containers
- Understand how to perform advanced container management
- Learn how to attach persistent storage to a container
- Learn how to manage containers as services
This course is ideal for anyone who wants to learn how to run containers with Red Hat.
To get the most out of this course, you should have a basic understanding of Red Hat and of how containers work.
It's now time to get our hands dirty, we are going to have a look at the guided exercise, it is all about Attaching Persistent Storage to a Container. So, to get things kick-started from a terminal on the workstation virtual machine we are going to be running the command lab container-storage start.
As you can see we need to have our successes before proceeding. So step 1 has us make an ssh connection as a normal user student to servera. Once we have done that what we are next going to be doing is creating a directory. So, go ahead, run the command mkdir -pv so, in the student user's home directory we are going to create a directory called webcontent and in that directory we are going to create a sub directory called html. So, now we need some content right! so, let's go and install some content. Here we have the command echo "Hello World" so, we are going to redirect that text into the web content directory into the html subdirectory to a file called index.html and guys as you can imagine this is the directory on the container host and we are going to take the contents of this directory and we are going to make it available inside of our running container. So, all that we need to do right now is validate that the permissions facilitate an unprivileged user or whichever user the container is running as, we need to make sure that that user's got permissions to read files in the directory webcontent and then html. So, run the command ls -ld and you should see that other has got read and execute permissions and then for the file index.html you should find once again that other has the read permission. So, moving on right now guys what we are going to be doing is creating a container from an image and this image is available at registry.lab.example.com.
So, over here I am using the command podman login -u specifying the username and the password to authenticate to the registry located at registry.lab.example.com.
So, right now what are we going to do is use the podman run command. So, yes we are going to run a new container, it's going to run detached. The name of this container is going to be myweb.
We, are going to be doing port forwarding so, we can access our content. So, over here we are forwarding the unprivileged port 8080 on the container host to the container the container running the web services on port 8080. So, here's the new thing, the thing that we had just learned about here we are doing a volume mount. So, over here we are saying take the directory webcontent in my home directory take webcontent and make it available inside of the container at /var/www. Now afterwards you may notice that there's a colon and then that's an uppercase z that allows us to set the SELinux context or the type context to be specific to container-file-t. So, we are running a container using the image registry.lab.example.com/ rhel8 and here we have the container image it's called httpd-24 and then you may notice that we are specifying a tag so, the tag that we are using is 1-98. So, what it's doing right now because the image is not available locally, it's downloading the blobs for that particular image and now if you run the command podman ps you will find that you do indeed have a container running.
So, here's the container, you could see the image from which it was started, you can see the command, you can also see over here guys that it's up and running and that we do have port forwarding configured. So let's go and have a look at the output of curl localhost and port 8080 and now we see 'Hello World', so this tells us that our volume mount worked. We were able to take the web content directory from servera and make it available inside of the container.
So, let's go and move on to step 4. So, over here I am using the skopeo command and we are having a look at the image. So, we are inspecting the image httpd-24 and I am just doing a grep over here, I know it's not in your student guide but I am doing a grep, I am showing you the five lines after the regular expression RepoTags is found, otherwise we are just going to get flooded with text.
So, what you could see is that we do indeed have several different versions of that same image.
So what we had done previously is that we had started a container using the image with the tag of 1-98 and now we see oh! look at that, we have other versions available as well.
So, what we want to do right now is that we want to stop the old container. The old container that was instantiated from the older image and we want to run a new container using a newer version of the image but we want to retain our data. So, next thing that we're going to do right now is run podman stop myweb. Now it stops the container but it doesn't actually delete the container.
So, now we run the command podman rm. So, moving on to the next instruction what we are doing now is using podman run. Yes! we are going to run it detached, we are going to give the container the same name myweb, we again are going to be doing port forwarding 8080 on the container host to 8080 in the container. Once again we are going to do a volume mount so, we're going to mount in the current user's home directory webcontent is going to get mounted to /var/www and don't forget we need to take care of that SELinux element. So, colon and that's an uppercase Z once again and this time we are specifying the newer version of the image.
So, you could see that again we are using httpd-24 but we are using the tag 1-105. So, of course we need to make sure that the image is available locally so, it downloads the image.
So, once the bits have been downloaded guys what we can then do is move on to step five three where we are going to be running the command podman ps. So, you could see that we do indeed have the container running and it is running from the newer image. So, all that we now need to do is make sure that we can access the same content. So, using the curl command accessing localhost on port 8080 and of course that is the port that is forwarded to the container to the container's port 8080. We see the same, we see the same data and that means that we were able to persistently use that storage and we were persistently able to use the storage across containers. So, guys once you are satisfied, do log out and to wrap up all that we now need to do is make sure that we run the command lab container-storage finish and that we have our successes and with that it brings to an end this section, I will see you in the next video.
Jeremy is a Content Lead Architect and DevOps SME here at Cloud Academy where he specializes in developing DevOps technical training documentation.
He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 25+ years. In recent times, Jeremy has been focused on DevOps, Cloud (AWS, Azure, GCP), Security, Kubernetes, and Machine Learning.
Jeremy holds professional certifications for AWS, Azure, GCP, Terraform, Kubernetes (CKA, CKAD, CKS).