Imran: Hey beautiful people
and welcome to the lecture
where we are going to discuss everything about containers,
running containers in a Linux environment.
So, first thing first, what is a container?
The term container and the concept behind it
came from the shipping container.
Yes, if you look at this picture right away,
this is a physical container which holds
all the different type of cargo shipment,
and it actually can transport it
to everywhere in the world.
So these containers are shipped from city to city,
and country to country.
No matter which part of the world you go to,
you will find these exact same containers
with the exact same size or measurement.
You know why they are built with the exact same measurement?
Because around the world all the docking ports,
ships, trucks, warehouses
are all of them built to easily transport
and store them so they don't have to buy different trucks,
they don't have to buy different lifts
that will lift them up to store them.
So everywhere you go in the world,
it's exact same size,
and that's what makes the transportation a lot easier.
So, that's visualize it.
So, you take that container
and you put it on a truck,
and then that truck goes to the docking station,
put that onto the ship.
Then what happened is this ship has to be transported
from one end of the world to another end,
and then on the other side of the world it actually lifts
that container and actually put it on the truck,
which can hold the similar, same measurement size
of that container and it ships over.
All right, so that's what it was about.
In a very basic or layman's term,
how the container came from.
Now let's look at the container in IT world.
Now, when we are talking about containers in IT,
we are fulfilling somewhat similar purpose.
In old days, so there was a developer,
she would write a code in her laptop,
and while she's writing a code,
the purpose of writing the code is to,
she could create an application.
So, once the code is written, the application is built,
she tested it on on her laptop,
then she copies that same code,
or that same software to a production server.
Then the production server,
we will open up that package or install the package.
Then we will try to run it and somehow it won't run.
Then what will happen is the developer will come back,
or the program will come back and says,
"Hey, it runs on my computer perfectly,
but it doesn't run on the production."
That's why the main reason these containers were born.
So, then came the containers technology,
which allowed developers or programmers
to test and build applications
on any computer just by putting it in a container.
The container is built within the,
with the software code, libraries,
and configuration files.
And then run on any computer regardless of its architecture,
it doesn't have to come or shipped
with the operating system.
So, you can move that application
within that container anywhere
without moving its operating system.
Which is just like moving the actual physical container,
which we'll discussed anywhere that will fit
on any dock yard, truck, ship or warehouse.
So, an operating system can run a single
or multiple containers at the same time.
To summarize, again, I'm sure these two slides
have made it a lot clear what a container is.
It is just a combination of your source software code,
libraries, and configuration file,
and no operating system.
You could move that container anywhere
from one machine to another and it will run flawlessly.
Okay, here is a note that you need to understand.
Container technology is mostly used by developers
or programmers who write codes to build applications.
Now, as you as a system administrator,
your job is to install, configure, and manage them.
Your job is not to write a code
and package it together,
and create an application out of it.
All right, moving on.
What are the container software?
So, let's talk about what are the software
that are available that actually manages these containers?
And the very first one in the line is the docker.
I am sure you have heard of docker many times,
and again this docker concept came from the same way
as a container.
The container where you actually land these containers
are the docker yard.
So, they got the name docker from the same dock yard.
So, docker was developed by Solomon Hykes,
in March 20th, 2013th.
docker is the software used to create and manage containers.
Just like any other package,
docker can be installed on your Linux system,
and a service or daemon can be controlled
through Native Linux service management tool.
By the way, docker is not only specific to Linux,
there are other versions of docker that can be installed
on Windows too, to provide the same container technology.
All right, then comes in podman,
which is the focal point for this entire lecture,
or the rest of this lecture.
podman was developed by RedHat and it was released,
the first release was sometime in August, 2018.
The podman was developed as an alternative to docker.
Now, why they made it and why they didn't like the docker,
I cannot answer that. (chuckles)
But anyway, for those who are using RedHat Linux,
you should know that docker is not supported in RedHat
Enterprise Linux 8.
So, you would have to go to with a podman.
Okay, it is a daemon less, open source,
Linux native tool designed to develop,
manage, and run containers.
Of course just like docker,
but it is RedHat's own developed software
to actually run containers.
There are many other containers, applications,
engines, and softwares are out there,
but I am only covering docker and podman.
If you wanted to learn more, what are the other software,
feel free to search it online.
All right, moving on.
Getting familiar with the RedHat container technology,
now we are getting into the actual RedHat.
Now, we moving away from docker.
So, now we are focusing on podman.
So, what are the RedHat container technology?
RedHat provides a set of command line tools
that can operate without a container engine.
These include a podman for directly managing pods,
and containers, images for example, running, stopping,
starting, ps, which is checking the status,
attaching the containers, et cetera,
you use this utility called podman.
Then you have another one called Buildah
for building, pushing, and signing container images.
Then you have Skopeo for copying, inspecting,
deleting and signing images.
RunC for providing container run and build features
to podman and Buildah.
And the last one is CRun an optional runtime
that can be configured and give greater flexibility,
control, and security for rootless containers.
Rootless containers are the containers
where you do not have to be root
in order to create or run these containers.
Anyway, from this point on,
our focus is only gonna be on the podman,
which will be used to basically create
and manage the containers.
All right, now next thing is getting familiar
with podman container technologies.
So, when you hear about containers
then you should know the following terms as well.
The first one is the images.
Containers can be created through images or from images,
and containers can be converted to images as well.
Just like for those who understand the term template
in virtualization environment,
you could create a virtual machine
from template or you could actually convert
a virtual machine to a template.
The images works as same as those templates.
Then the next one pods.
Pods are the group of containers deployed together
on the host, or on an operating system.
In podman logo there are three seals
grouped together as a pod.
You see this logo?
That's the logo and these three seals that represents
the group of containers running at the same time.
All right, now let's get into building,
running, and managing containers.
Let's get our hands dirty
and run our create containers.
All right, the very first thing we have to do
is to install podman.
Again, podman is a command line tool
that allows you to create or manage your containers.
The first command you have to do is yum/dnf,
to install a package.
So you will have to do dnf install podman and -y option
to say yes to all the questions
that will be asked during installation.
If you are doing a docker install,
you could do the same way yum install docker with -y option,
and that is only for dockers.
So, what I'm gonna do is
I'm gonna start up my computer,
which runs of course the Linux machine.
I have RedHat 8,
and I also have CentOS 7.
So we will run both of them at the same time,
and some of the commands I'll cover in RedHat 8
and some of them I will cover in CentOS 7.
All right, so let me start up,
let me go to my Oracle VirtualBox.
This is where,
this is where my virtual machines are running.
This one, my first Linux VM
is my RedHat 8 and this is 7,
which is running CentOS 7.
So, very first thing I want you to do
before you even power it on or start up,
I want you to take a snapshot.
So, right here it is already on the Snap Shot menu,
and click Take,
and you can name it
Before Containers. (clacking)
So, in case you wanted to revert back,
something goes wrong while you're downloading,
you could always revert back.
Click Okay, same thing with 7,
click Snap Shot, Take.
Before Containers. (clacking)
Okay, perfect, now let's go ahead and start
both of these machines.
This is 8 and this is 7.
I'm covering both 8 and 7.
So, those who are practicing Linux,
or Linux Containers on 7,
they would be able to understand how these commands
are similar and can be,
can be run on both operating system versions.
Okay, so I have my RedHat right here,
and I have my CentOS 7 right here.
So, I'm gonna leave them right next to each other,
side by side.
First we will run the install command on RedHat 8,
and I will use the command dnf install podman
with -y option,
so it could answer yes to all the questions
during the installation.
Similarly, I will run same command,
except I will replace dnf
with the yum install podman -y.
Okay, so depending on how slow, how fast your computer is,
it could take anywhere from a minute to five minutes.
All right, on RedHat 8,
the download and installation of podman has been completed.
On CentOS 7 it is almost there,
running transaction check, updating,
and it should be done in any minute anyway.
While we are waiting for that,
let's go ahead and run the next command,
which is to create alias to docker.
Now, this command is only for those
who have a docker running
on their Linux machine and now they wanted to use podman.
So, you could simply create an alias
for your docker to podman.
So, which will still run all the commands of docker,
but it will run through podman.
So, we will leave that as is
because we never had docker running before.
The next command is check podman version.
So the podman that we have installed,
let's check his version
by running the command podman -v,
the version is podman version 3.0.2.
Let's check the other machine is still updating.
Let it run.
The next thing is getting help.
So, if you need any help regarding podman what options,
what commands to use,
you could use either podman --help,
or simply go to the manual pages of podman.
So if you, let's clear the screen,
if you type podman --help and hit enter,
you will get all these different options,
and if you scroll up,
you will see all these optional commands
that are available with the command podman.
You could attach auto-attach, build, commit, container,
copy, create, diff, export,
all these commands are options
that are available with your podman command.
You could also check all the options
that have available to you
by running the command man podman.
It's just a regular man page.
Hit enter, and here you'll see
it will give you all the documentation
about podman simple management tool for pods,
containers, and images.
As you scroll down by hitting the space bar key,
you will find all the different options
that is available under podman.
Let's go check on our CentOS machine.
That's where okay the...
The installation has been completed. Beautiful.
Now we will run the same command here,
podman -v to check the version.
This one gives us a different version
because it is running
on a different operating system version.
That's fine, same way, podman and --help,
give you all the help that you need.
You can also do man podman,
and you will get the manual page,
just like as we do on 7 or sorry on 8.
Then moving down to new other commands,
check podman environment,
and it's registery or repository information.
So, when you run podman info,
so if you are trying to load a container image
then it will look at the local machine,
then go through each registry by the order listed.
Now, what are those listed registry?
Let's take a look, let's do podman info.
And here you could just scroll up a little,
and right here where you'll see registries, search.
If you wanted to search for a Pacific image,
it will go to its local machine
to see if it has any images
that you're looking for.
If it can't find it then it will go
to registry.access.redhat.com.
Then it will jump to registry.redhead.io,
and then on last it will go to docker.io.
Wherever it could find the image
that you are looking for.
So, here's the same way,
let's clear the screen podman info,
and same information
will be given to you right here, registry.
Three different locations where you could get your images.
All right then the next command
to search a specific image in repository.
So, let's say you build a machine,
you already have a podman, the tools that you need.
Now, it's time for you to run a container,
but before you run a container you don't have to go in
and build a container.
There are pre-built containers out there,
and those are packed together in something called an image.
So, we have to look for the container image.
So, in this example we will look for httpd image.
So, let's come down, clear the screen and do podman,
hey podman search for a, sorry, not container,
search for an image called httpd.
And again it'll go to all those repositories,
registries that we looked at when we ran podman info
and it will pull the information.
So, right here it pulled all the information about images
that where you could find the httpd.
Now, let's go up,
and right here when we ran the command
here is the title of this table.
The first one tells you this is the index,
this is the name, description, these are the stars.
The stars the actual user had given to this image.
Is it official, is it automated?
All the information is there.
So, as you come down you'll see there are zero stars,
probably nobody has used it.
We will go down and look for the stars
that has the highest stars.
So for example, right here, it says docker.io.
The image that you're looking for can be found
in docker.io/library/htpd,
and it has 3616 stars.
So, right now at this time while I'm recording this video,
it is showing 3616.
Maybe by the time when you run this command
you will have a different number.
Anyway, so we know that this one
is definitely a lot of people
have checked it out, they have downloaded this image.
So, we will use the same image
or same location to download the image.
All right, for that what do you have to do?
So, let's go to the next screen,
and here to list any previously downloaded podman images.
So, before we pull this image down,
let's check if I already have any images
running on my system.
I'm sure there isn't because I never had podman before.
So just to show you the command to check
is podman images,
and it is telling you the title of the image,
the tag, the image,
but there isn't any information underneath it,
it means there aren't any images available.
Similarly, in CentOS 7 podman images,
and nothing will be found.
Perfect. Now, moving on.
Now, we already verified we don't have any images.
So what's the next step?
Next step is to download the available image
and that available image can be downloaded.
We'll look for http and we know that image is available
on this registry.
So to download that we have to use the command podman
with the pull, since we are pulling it down.
let's clear the screen and do podman pull.
From where? From docker.io/library.
By the way this URL that I'm putting it down,
or this registry information I'm putting down,
I got this information when I ran the podman info
with the stars, remember 3616?
That's exactly what it is /httpd.
Hit enter, it will go to that registry
and pull the available image
that's already sitting here on this URL,
and then pull it down.
Same way here, clean the screen, podman pull
docker.io/library/httpd,
and it's gonna pull it down.
Okay, by the way,
up until this point you guys have seen
and confirmed a few times
that all the commands that I'm running on 8
are pretty much working the same way on 7.
So, what I'm gonna do from this point on,
I'm just simply gonna minimize 7 and all the commands
that I'm gonna run after this point
I will be running on 8.
So, it doesn't matter if you have only 7,
you could just follow along.
All right, so the podman pull docker image
has been downloaded.
How do we confirm it has been downloaded?
You could run the same command podman images,
and right now this is telling you, hey I got this image.
This is the image ID and the repository came down.
This is the repository, it's tag is latest.
It was created 51 minutes ago.
Wow, someone has modified,
and then the size of this is 142 megabyte.
All right, beautiful.
All right, so we already checked the images,
images have been downloaded.
Next command to list podman running containers.
So, we have the image and now we need to run the container,
but of course before we run it,
let's check if we have any existing containers running.
Of course we don't but we still wanted to check
because I want you to learn the command,
how to check the existing running containers.
And for that you have to run podman ps.
Again, just like podman images,
we have the title line up here but we do not have
any other information about the containers
telling me the container, ID, image, command,
created, status, ports, names,
but there is an actual container.
So, we have confirmed nothing is running.
Now what's the next thing? Now we have to run the container.
Okay, to run a downloaded http container,
which we just downloaded,
this is the command we have to run.
Let's clear the screen, podman run.
And by the way, let me just quickly go back
and tell you more about these options.
D for detach meaning I want my terminal back,
t for terminal tty shell,
my prompt shell, and p- option p is for the port
that I'm specifying for this http container.
And then of course we'll run podman ps
to check if that container is running.
All right, podman run -dt, -p for port,
8080:8 for tcp,
sorry, 80 for tcp.
And then where is the registry?
docker.io/library/httpd.
Now, how do we check if we have
our container successfully running? Good question.
For that you have to do podman ps,
and here it is your container ID.
The image where it actually downloaded the image from,
the command, created 19 seconds ago.
That's when I ran this command.
Status up 18 seconds ago.
And this is the port, this is the IP,
which is the local host.
This is the port that we specified for http,
the tcp, and this is loving_wilson,
whoever actually named this image
to whatever they wanted to give.
So, you could give it any name as well if you want.
You could give when you create a a container out of image,
you could give it any name you like,
which we'll cover in a second.
All right, beautiful.
So, we have confirmed that the container is running.
There is another way you could confirm
whether the container is running by going to your Firefox.
And type localhost:8080.
Localhost is the IP address of my machine.
I could have used it 0.0.0.0, that's fine.
And the port 8080,
remember the port 8080 we specified for this http.
Hit enter and right here I got the page that says it works.
Brilliant, so if you are here,
and you're following me here
exactly up to this point, it means you got your container,
your very first container running, so congratulations.
All right, let's close this.
We have confirmed that it is up and running,
so let's close this down.
Now, next thing,
what we need to learn is to view podman logs.
Anything that we wanted to learn,
if podman is not running the container successfully,
you could definitely check the logs.
Podman logs -l, and it will tell you
all the information that you need
as to when it started,
how is it working, and all the information that you need
to troubleshoot further.
Let's clear the screen.
Let's go to the next slide to learn more
about building, running and managing containers.
Now to stop a running container,
you could just simply do podman stop and a container name
or container ID.
So, how do we know what is the container name or ID?
For that you could just simply run podman ps,
which give you the status of your container.
And the container ID is right here,
which is in the very first column,
if you wanna stop this container,
all you have to do is podman stop.
And this container ID,
you could just right-click copy and come back here,
Right-click and paste and hit enter.
And it should stop by giving you your prompt back.
How do you confirm it actually has stopped?
If you have answered podman ps,
then you are absolutely right.
There you go.
You just ran it and now you don't see any container running.
Awesome. Okay, moving on.
We checked the podman ps.
Okay now to run multiple containers for httpd
by changing the port number,
what if you wanted to run two containers
out of the same image,
you could run the same command,
but you have to specify a different port.
So, just like that is we are,
I'm picking 8081,
and in the second one I'm picking 8082.
So, let's clear the screen.
I'm gonna bring back my previous command
by hitting the up arrow key,
which will bring me the command that I ran to start,
or to run the container.
So, I'm gonna do 8081, enter.
This has started and I'm gonna do 8082.
So, now this is going to start two containers
out of that one image, hit enter.
And how do we check,
if I have two containers running podman ps.
And here you have one container right here,
and this is the second container right here.
This is on port 8081 and this is on port 8082.
Now, if you go back to your Firefox
and specify local host 8081,
and on another tab, you specify 8082,
you will get a similar result.
All right, we check the podman status.
Now, to stop and start a previously running container,
you could just simply do a stop, which we already covered.
You could stop it, and you could stop it as well.
So just to cover this piece,
we could just simply stop one container,
so we could stop 8082.
So, podman stop,
and the container ID,
copy and paste.
Hit enter, it should stop.
How can you confirm podman ps,
and only one container is running at this time now.
All right, moving on.
To create a new container
from the downloaded image.
Okay, so pay close attention.
When we downloaded the image earlier,
we actually ran that container straight out of the box.
Now what if you wanted to download,
make certain changes to that image
to a way that you wanted to look or function?
Or maybe instead of it works,
you wanted to put your name Imran Afzal,
or something like that.
Then you have to change its code,
and then create the another new image out of that.
Okay, so for that what you have to do,
let's clear the screen.
What you have to do is you have to type
podman create --name.
Now, what name do you want to give it to?
Here I have given httpd you could give your name as well
just for fun of it.
But anyway, to be consistent we'll use httpd.
It doesn't have to be httpd, it could be anything.
Now, where is the registry?
Registry is docker.io/library/httpd.
All right, it has created the container.
Now, how do you check the container?
We do podman ps.
So, it is running only one container,
which is recursing_liskov, not httpd.
So, that means it actually created the image
out of that podman container and created the container now.
How do I start that container that I just created
out of that image, this one?
For that you simply have to do podman start
and the container name, which is httpd.
There you go, it has started. Beautiful.
Now, you should have two containers,
running one container.
Here's the container you got it running.
Right out of that package,
that, sorry, that image.
And this is the second container
that you're running that you created yourself, beautiful.
Now, to start the newly created container,
you could do a start httpd.
We are one step ahead. We already did that.
Beautiful. Now, what is next?
Now, next step is what if you want
to manage your containers?
Meaning when your computer boots up,
what if you wanted your computer to boot up
that httpd container with the system?
So, of course as you know that to boot,
or to control any boot processes
that is managed by a process called systemd.
So, we have to notify systemd process.
Hey, there is this new process
that you have to run every time the system boots up.
So, for the very first thing we have to do
is to first you have to generate a unit file.
A unit file can be generated with the podman.
Why do we need a unit file?
Because if you come down,
there is this directory called etc/systemd/system,
you have to put that file,
which is called unit file into this directory
in order for systemd to know,
hey, there is this new service, it has to start.
So, let's clear the screen,
let's go to etc/systemd/system.
And when I do ls -ltr,
or ls -l,
whatever you wanna do, you see all these targets,
all these services have been defined in this directory
to be started during boot time.
So, I have to create this service file,
which is called Unit,
and I have to copy that into this directory.
Very simple for that,
what you have to do is we have to run the command podman
because podman will generate that unit file for us.
Generate systemd --new --files
-: -name, and what name do you want to give?
This will be the name that you have given to your container.
If you had given in the previous command,
when we created the container
from the image using the command podman create,
and we given the name you have to use
that same exact name, hit enter.
And right here is telling you the container
etc/systemd/system/container D, it's there,
it's already been copied over, which I did previously.
If you do not get this message,
you most likely you will get the message
that it is in /root,
/rootdirectory, and when you do
ls -ltr it will tell you,
hey, it is in this directory.
Anyway, if you don't get it,
then it means it's already in there.
So let's go to etc/systemd/system
through ls -ltr.
And right here at the bottom you see it has created
this unit for our http container.
Beautiful, beautiful, okay, then what do we have to do now?
Enable the service because we want the service
to start a boot, so we have to enable it.
So systemctl enable,
container-httpd.service.
It is creating this symbolic link. Perfect.
What's the next step now?
If you remember, you have to start the service.
To start the service, you have to do systemctl
start, the container unit file, hit enter.
If you don't get an error,
it means your service has been started.
Now, how do you check the status of that service?
You could just simply do status.
And you will see right here,
it is active and it is up and running.
Excellent. So we learned so much in this container video.
You should know what a container is now.
How do you build it, run it,
and manage it in Linux environment, good luck.