Guided Exercise: Running a Basic Container

Developed with
Red Hat

Contents

keyboard_tab
Introduction & Overview
Managing Containers as Services
Review & Lab Session
Start course
Overview
Difficulty
Intermediate
Duration
1h 46m
Students
65
Ratings
3/5
starstarstarstar-borderstar-border
Description

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.

Learning Objectives

  • 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

Intended Audience

This course is ideal for anyone who wants to learn how to run containers with Red Hat.

Prerequisites

To get the most out of this course, you should have a basic understanding of Red Hat and of how containers work.

 

Transcript

Time to get our hands dirty, here we are going to have a look at the guided exercise, it is all about Running a Basic Container. So, what we ought to do is to open up a terminal on the workstation machine and then from there we are going to be running the command lab containers-basic start and as you can see I am geared up for success.

So, let's go and move on to the first item. So, we are told to make an ssh connection as the user student to servera. It's not prompting me for a password because we are using ssh keys and then from there what are we are going to be doing is installing the container-tools yum module. So, the command is sudo yum module install -y container-tools and you guys are really not interested in seeing all of the packages being installed, right! So, I am just piping it out to the tail command and I am showing you the last four lines and as you can see that transaction is Complete. Now in order for us to get started with containers, we need an image, right! so, in order for us to get an image we need to connect to an image registry. So, what we are doing over here is that we are using the podman login command and yes I know that is bad practice, you are looking at that thinking crikey! I can see the username and password. Guys, I am just doing this so that you can see that I am logging in as admin with the password of redhat321 to registry.access.redhat.com and that is a registry that we have running internally.

So, from there I want to show you right now all of the images that we have downloaded. So, running the command podman images, well it reveals nothing, there are no images that we have downloaded. So, what we could do right now is that we can use the podman pull command so, we can connect to a registry and we can download an image. Now using the podman pool command doesn't actually start a container. What it does is that it downloads the image. So, the command over here is podman pull. We identify the registry so, it's registry.lab.example.com slash and then the naming convention very often includes the username or the team name or the vendor name afterwards slash then we have the name of the image. In this case it is httpd-24 and then we have a colon followed by the tag. So, the tag facilitates version control, right! Now if you omit the tag, the tag latest is always going to be assumed. So, you can see that it's downloading the various blobs over here and ultimately we have downloaded the image right now. So, now that we have an image, what we could do is start a container. So, let's have a look at this command over here. So, we are saying podman run, we are going to be running a new container and we are going to give it a name. Now if you omit the - - name, a name is going to be  randomly generated for you. Ultimately guys how we identify our containers, how we identify images are by their IDs. So, what I could do is that I could either address this container by using the name myweb or by its ID. So, the name of this container is myweb and the options that we are going to use over here include -it, so that we can get an interactive terminal. So, when you run a container you have to specify the image.

So, the image that we are using is the one that we have just downloaded. Now pre-downloading your images reduces your time to market because while you can just say podman run and you could specify the image even if it hasn't been previously downloaded, it's going to have to download it first and depending on the size of the image of course that could take a couple of seconds.

So, by pre-downloading it, it reduces the time to market and I am saying well what are we going to do right now, is get a bash shell into that particular container. So, over here guys, I am running the ps aux command and you could see the processes that I am running in the container. Also looking at the id command over here, you could see that in the container I am logged in as the user default which has a user id of 1001. So, by exiting right now what it does and this is because of how I start to the container. It actually stops the the container. So, the next instruction says that what we are going to do is reference that same image, we are going to use the podman run command. Now when you run a container, when you stop it, it doesn't automatically delete that container.

So, it's data is still available afterwards. So, in this case over here we are saying podman run and then once the container has run, once you are done using it, what we could do is that we could delete it so, that it doesn't occupy precious space. Also in that case over there you may notice that we have omitted the - - name. So, we are not using a static name, a name is going to be generated for us.

So, all that we're doing over here is that we are showing you that we are using the image registry.lab.example.com/rhel8/httpd-24 and as you can see we are not specifying the tag so, the tag latest is going to be assumed and the command that we are running is httpd -v. So, what it does over here is that it simply returns the version of httpd.

So, I know that this is not formally part of the guided exercise but I feel like I want to show you a couple of additional things. So, I am using the podman ps command over here and you could see that yes we don't have any containers. So, let's go and run a container right now.

So, if you have a look at this command, I am using podman run -d so, the -d tells it to detach. Run the container but do not run it in the foreground, detach it so that kind of runs in the background. So, the container over here that I am using is based on the image registry.lab.example.com/rhel8/httpd-24:latest. So, guys because the container image was deleted what I am now doing is that you could see that it's downloaded the various blobs and I want to show you the output of podman ps. Now remember if you don't give your container a name, one is going to be generated for you but how we ultimately identify these these containers would be by their container ids. Now what I like to do is that I like to reference it by id because this is the convenient part, okay! When I double click the container id, it automatically highlights the entire string and it's quite convenient that now I can go and copy it and I can go and paste it rather easily.  So, here's my container, it is identified by the id beginning with 388 and what you can now see is that here we have the registry that the container was started or the image that the container was started from.

Then you can see the command that was invoked, to start that container you can see when it was created of course this is relative and you could see how long it's been up and running for and then here you could see quite an interesting name isn't it but here's the dynamically generated name it's called goofy_goldwasser.

So, let's go and have a look at the output of the command podman images. So, you can see that the image has been downloaded, it's been downloaded from the registry.lab.example.com image registry, the tag is latest and again we identify these things using their image ids. Of course you can reference the name but what I really like is that you simply go ahead and you double click the id and it highlights the entire string. You could see when it was created and the size so this is 430 megabytes. So, again the advantage of pre-downloading your images using the podman pull command means that when a user requests a container, when you need to run a container, the image is already there we don't have to go and re-download 430 megabytes of data.

Now the other thing that I want to show you over here is that I have got my container that's a goofy_goldwasser and you could see that it is running detached, it's running in the background.

So, it's happily doing what it does best which is to be a web server. So, I want to connect to that right now I want to interact with the container. So, the command that I have used over there is podman exec. So, I am saying give me an interactive terminal and instead of addressing the container by its dynamic name, I am using its id. So, I simply copied and pasted from the previous tab and I am saying give me or run the bash shell. So, let's run the bash shell, I have a bash shell running right now. So, I have just run the id command and you can see that I have run the command ps -ef. Now why I am showing you this is because I want to show you the grand total of processes that are running inside of this container and this goes to to further emphasize that this is a completely isolated environment. So, this is isolated from the hosts file system from the host environment.

So, all of the processes running over there you can see that I have got httpd coreutils bash and the ps -ef command was running at the time. So, do you notice the omission of systemd, yeah there's nothing else over there that this is all. This is all that I need to support my particular application. So, what I also wanted to show you over there was in this case I have tried to run the ss command. Now I knew that that command wasn't going to work but I still wanted to show you what it says because the ss executable is not present in the image.

So, you can only run those commands, you can only run those binaries, you can only use those libraries, you can only use those resources that are present in the image. So, if something is not in the image like the ss command, well then it's going to simply say that the command was not found. So, guys I have just exited from that container right now and because I have exited the container it takes me back to the shell of the host. So, what I want to do right now is that I want to show you the output of podman ps. I exited the container, I didn't stop the container. So, you could see that looking at the output of podman ps. You could see right now that my container goofy_goldwasser is still there, it's still running in the background. So, if you wanted to stop it well the command is really simple podman stop goofy_goldwasser and as you can see I use the name of the container.

So, when you run the command podman ps afterwards, you'll see that yes the container is not running anymore, however it's still in an archive state. So, looking at the output of podman ps -a you could see that I still have the containers data that is still present on this particular container host. So, you could see that it does reference the container and you can see its id, you could see the image that we were using in that command, you could see the exit status the return code over there. Remember 0 means good and this happened 12 seconds ago, well 12 seconds being relative to when I ran the command. So, what I really like about this is that these archived containers. It gives me the opportunity to have a look at logs. It gives me the opportunity to try and figure out what happened if the container maybe be didn't run successfully. So, guys when you run the command podman run and you use the - - rm what's going to happen is that when the container stops, it's going to delete it, it's going to delete it so, the archive container so that you can't actually go ahead and access the logs. You can't go and do further troubleshooting. So, if you are having difficulties running containers using podman run - - rm is not convenient.

You only want to run or use the - - rm option when you have established the container to be working well. You've set up all the bits and pieces and you know that when it runs, it's going to run and that no further troubleshooting is required. So, what we can see over here is that podman logs tells us that here we go. This is the output of the entry point of the command that is used to start up the container. So, you can see all that output over there.

So, let's move on. So, what I am doing over here as well is that just remaining on servera.

I have run the command podman ps -a, you can see that the container is still there.

If you want to remove an archive container you would say podman rm and then you could of course specify the container by its id or by its name and then finally over here guys I have just run the command podman ps -a to show you that the container has finally been deleted.

Now after that free forming all that we need to do is wrap up and we need to do that by running the command lab containers-basic finish. Make sure that you have your successes before continuing and with that guys it does bring this guided exercise to an end I will see you in the next video.

About the Author
Avatar
Jeremy Cook
Content Lead Architect
Students
91619
Labs
52
Courses
110
Learning Paths
81

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, GCP, Azure), Security, Kubernetes, and Machine Learning.

Jeremy holds professional certifications for AWS, GCP, and Kubernetes (CKA, CKAD, CKS).