In this session, I describe how WordPress builds their official images by traversing through its official Dockerfile and it's series of dependencies on php-apache, debian docker images all way down to scratch.
Next, I build a custom Dockerfile that would create our own custom docker image containing a customized runtime output. I then push our image to our own custom docker registry while describing how one could use Azure, Google, or Amazon container registries apart from Docker Hub.
WEBVTT
00:00.000 --> 00:10.440
And the recording will become available as a podcast in a location that you may or may
00:10.440 --> 00:11.440
not know.
00:11.440 --> 00:16.140
But if you go to my Twitter profile, you will see that there is this button right there
00:16.140 --> 00:17.640
meeting video recordings.
00:17.640 --> 00:20.560
If you hit on that button, it takes you to the podcast.
00:20.560 --> 00:23.980
That's where the recordings show up in Spotify.
00:23.980 --> 00:27.760
So today's recording will show up right here in like 24 hours.
00:27.760 --> 00:30.560
So that's where you can see the recording later on.
00:30.560 --> 00:33.480
And I am beginning our discussion.
00:33.480 --> 00:37.320
We are not streaming today for some technical reasons.
00:37.320 --> 00:45.600
Having said the topic for today is this, which you can read and it is about taking any application
00:45.600 --> 00:48.720
in any language that you have.
00:48.720 --> 00:55.560
And I will containerize it and run it in some cloud.
00:55.560 --> 00:56.840
That's the idea.
00:56.840 --> 00:58.400
So what is containerization?
00:58.400 --> 01:02.320
I think you probably kind of sort of know, but I will demonstrate that by doing it and
01:02.320 --> 01:04.720
then also describe as we go along.
01:04.720 --> 01:10.880
Now to containerize something, we need to have an application already that we will then
01:10.880 --> 01:14.960
run it directly first on the computer if you want.
01:14.960 --> 01:16.100
But that's not the goal.
01:16.100 --> 01:21.320
The goal is to containerize it and then run it inside a Docker container so that we can
01:21.320 --> 01:24.660
take that container image and put that in a cloud.
01:24.660 --> 01:30.640
So that's the portions that we will basically deal with where to get an app already.
01:30.640 --> 01:32.280
If you have an app, give it to me.
01:32.280 --> 01:37.760
If you don't have an app, I will get an app from somewhere open source.
01:37.760 --> 01:43.520
And then containerize it like that's the meat of the discussion today is taking an app and
01:43.520 --> 01:44.520
how do you do that?
01:44.520 --> 01:46.280
That's the most of the discussion.
01:46.280 --> 01:52.560
And then once you have it containerized, running it in any cloud is a subsequent step.
01:52.560 --> 01:56.080
We'll do that also later on.
01:56.080 --> 01:57.080
Probably not.
01:57.080 --> 01:58.080
It may not happen today.
01:58.080 --> 02:00.040
Just so you know, it may extend into another session.
02:00.040 --> 02:04.160
So we'll take this application and begin the direction.
02:04.160 --> 02:08.160
Apparently, you don't have any app to give it to me, which is fine.
02:08.160 --> 02:10.840
So I'll just pick an app myself.
02:10.840 --> 02:16.000
What I intend to pick is what we discussed briefly in the last session about an application
02:16.000 --> 02:19.600
known as WordPress.
02:19.600 --> 02:23.800
This is a open source product.
02:23.800 --> 02:25.400
It's available from here.
02:25.400 --> 02:30.080
You can download it and install it.
02:30.080 --> 02:31.160
And how do you install it?
02:31.160 --> 02:34.200
You read the installation guide.
02:34.200 --> 02:37.920
And this is the installation instructions.
02:37.920 --> 02:43.840
So we'll basically follow these instructions in a manner that will help us run this application
02:43.840 --> 02:49.920
in a container, in a Docker container, not directly on a computer, but in a container.
02:49.920 --> 02:52.680
That's the idea.
02:52.680 --> 02:55.200
So we will begin doing that.
02:55.200 --> 03:01.960
The easiest way, the cheat way, the cheating way is to not bother about containerization,
03:01.960 --> 03:08.720
but actually just use an existing image that these guys already created for us.
03:08.720 --> 03:12.640
So there is the WordPress Docker image.
03:12.640 --> 03:15.840
It's readily available already right there.
03:15.840 --> 03:19.600
You can just pull it if you like.
03:19.600 --> 03:21.760
And that's what I will be doing the first time.
03:21.760 --> 03:26.160
What I will do now is go to a Linux computer.
03:26.160 --> 03:29.200
By the way, what I'm working on is not Linux.
03:29.200 --> 03:31.880
This is a Macintosh.
03:31.880 --> 03:36.320
As you can see, it's a Macintosh computer.
03:36.320 --> 03:38.740
It says Darwin.
03:38.740 --> 03:41.960
And so I need to go to a Linux machine.
03:41.960 --> 03:46.600
I already have a Linux machine at my hand right below my feet.
03:46.600 --> 03:50.720
And that machine is a iMac that runs Ubuntu.
03:50.720 --> 03:56.560
I will connect to it simply by typing this, like that.
03:56.560 --> 04:02.040
That takes me to an Ubuntu machine that is available.
04:02.040 --> 04:09.640
It has Docker already installed and lots of containers running already.
04:09.640 --> 04:16.120
What I want to do is get this ready-made container image already available.
04:16.120 --> 04:25.620
I want to pull it and bring it down to my Ubuntu machine so it's coming down.
04:25.620 --> 04:27.180
And then I have it locally.
04:27.180 --> 04:30.640
So that's the easiest cheating method.
04:30.640 --> 04:31.640
I already got it.
04:31.640 --> 04:34.200
I can just run it simply.
04:34.200 --> 04:36.440
And you already saw me running it in the last session.
04:36.440 --> 04:42.400
So that's how you can run it if you like a WordPress image running your own inside your
04:42.400 --> 04:43.920
Docker containers.
04:43.920 --> 04:45.520
But this is the cheating method.
04:45.520 --> 04:50.620
The easiest method is to use the ready-made images like this.
04:50.620 --> 04:52.840
But that's not what you're talking about.
04:52.840 --> 04:55.640
What we're talking about is to understand how they build these images.
04:55.640 --> 04:58.760
And so we can build our own.
04:58.760 --> 05:03.920
And so building our own images basically is a good idea to look at how people build images.
05:03.920 --> 05:07.580
These are smart people that make the software called WordPress.
05:07.580 --> 05:13.280
And they have built various image versions.
05:13.280 --> 05:21.800
And let's go find out the latest version that they have and look at what they built.
05:21.800 --> 05:29.960
So here is the latest Docker image that I just downloaded like that.
05:29.960 --> 05:35.880
And let us go see how they build this particular WordPress Docker latest image by looking at
05:35.880 --> 05:37.800
what is called a Docker file.
05:37.800 --> 05:40.960
So we'll go and examine what did they do to build that image.
05:40.960 --> 05:46.440
And the way to do that is to go to the source code for how they build this Docker image
05:46.440 --> 05:49.880
for this application, WordPress.
05:49.880 --> 05:55.540
So what I will do is go to GitHub, which is the place to usually find source code.
05:55.540 --> 06:03.200
And there I will look for WordPress Docker image GitHub.
06:03.200 --> 06:09.440
That should take us to the Docker library WordPress, where the code is to work for how
06:09.440 --> 06:14.080
WordPress people create this Docker image.
06:14.080 --> 06:17.020
Which one?
06:17.020 --> 06:18.560
This one.
06:18.560 --> 06:21.440
That's place called this place is called Docker Hub.
06:21.440 --> 06:26.560
That's where WordPress people are storing Docker images.
06:26.560 --> 06:30.200
And this is how they build it.
06:30.200 --> 06:32.120
This is the source code.
06:32.120 --> 06:36.800
So we're going to examine the source code and understand how they build it and then
06:36.800 --> 06:42.200
modify it to begin with slight small simple modifications we can make so that we can understand
06:42.200 --> 06:44.400
how this image is being built.
06:44.400 --> 06:48.880
And then as we go deeper, we can build everything from scratch our own.
06:48.880 --> 06:56.000
And let's first understand how did these guys build the Docker image on the left side using
06:56.000 --> 06:59.320
the source code on the right side.
06:59.320 --> 07:01.960
That's what I want to understand.
07:01.960 --> 07:23.960
So it is a file called latest that uses a Docker file here.
07:23.960 --> 07:27.360
That's the file, by the way, that they use to create the image on the left.
07:27.360 --> 07:30.520
So this is a fairly detailed file.
07:30.520 --> 07:34.840
So I don't want to scare you by going into straight into the details, but I want to simplify
07:34.840 --> 07:37.240
the understanding of how they built it.
07:37.240 --> 07:41.600
And then we'll begin small to construct our own images and then reach up to this level
07:41.600 --> 07:45.080
of understanding level of complexity needed to make this happen.
07:45.080 --> 07:50.320
I'm not scaring you by showing you a giant Docker file like this.
07:50.320 --> 07:53.720
It can be daunting to read and understand, so I'll simplify it.
07:53.720 --> 07:57.760
Make very small simple images to begin us begin, you know, take us the journey towards
07:57.760 --> 08:07.480
building complex setups to create our own Docker images that you can put on Docker hub.
08:07.480 --> 08:19.120
But you need to have a Docker file that you basically build to create this.
08:19.120 --> 08:23.240
So this is an image.
08:23.240 --> 08:26.200
And this is a source code for that image.
08:26.200 --> 08:31.080
Here are the instructions, step by step.
08:31.080 --> 08:39.860
It has a beginning point and subsequent steps like that.
08:39.860 --> 08:48.840
So I will now look at the beginning step for this particular Docker file.
08:48.840 --> 08:50.620
Where does it begin?
08:50.620 --> 08:53.400
It begins from something.
08:53.400 --> 08:55.400
What is that something?
08:55.400 --> 08:56.400
PHP.
08:56.400 --> 08:59.120
Why PHP?
08:59.120 --> 09:07.560
Because this guy, the instructions for basic instructions require you to have PHP.
09:07.560 --> 09:11.280
In fact, that's a requirement for this application.
09:11.280 --> 09:13.640
It requires PHP.
09:13.640 --> 09:17.700
And requires MySQL database or some other database.
09:17.700 --> 09:25.760
And it requires some kind of, it's called, you know, an application server to render
09:25.760 --> 09:29.780
what you see on the website that you create using WordPress.
09:29.780 --> 09:34.040
So it's called Apache as an example, is one of the web servers that you can use.
09:34.040 --> 09:36.140
There are other servers you can also use like NGINX.
09:36.140 --> 09:40.300
So basically you need a couple of things for this to run.
09:40.300 --> 09:46.680
You need something like Apache, which is a web server.
09:46.680 --> 09:50.440
You also need PHP, the language.
09:50.440 --> 09:53.880
That's what these guys are using.
09:53.880 --> 09:58.920
And you need some database like MySQL is recommended.
09:58.920 --> 10:01.320
And these needs to run on some Linux machine.
10:01.320 --> 10:05.240
You can also run it on other places, by the way, but we'll be using Linux.
10:05.240 --> 10:09.640
So that's the requirement for this Docker, sorry, WordPress application.
10:09.640 --> 10:13.400
One, two, three.
10:13.400 --> 10:21.440
And these two things, the first one and two are taken care of right here.
10:21.440 --> 10:29.560
So they're beginning with something ready-made, PHP and Apache already included.
10:29.560 --> 10:39.520
And they add certain things like WordPress itself in here to create the image needed
10:39.520 --> 10:41.720
for WordPress to run successfully.
10:41.720 --> 10:46.160
And then they add another container running MySQL separately, like just like we did the
10:46.160 --> 10:48.240
last time.
10:48.240 --> 10:51.320
So let us go investigate what this thing is.
10:51.320 --> 10:56.080
It contains two things, PHP and Apache.
10:56.080 --> 10:59.320
So let's go see what that image is.
10:59.320 --> 11:06.000
It is actually a separate image created by somebody else, not WordPress, not these guys.
11:06.000 --> 11:07.160
Somebody else created it.
11:07.160 --> 11:08.160
Who creates it?
11:08.160 --> 11:09.160
Let's go find out.
11:09.160 --> 11:11.800
Let's go find out who created this image.
11:11.800 --> 11:19.840
So we'll take that name, copy it, search it in Docker Hub, like that.
11:19.840 --> 11:25.520
We'll take this name, go to Docker Hub and search who created this.
11:25.520 --> 11:28.160
Oh, sorry, I copy pasted incorrectly.
11:28.160 --> 11:39.280
So who creates the PHP Apache image?
11:39.280 --> 11:40.280
Let's go.
11:40.280 --> 11:44.720
If it tells us the result, probably it doesn't give us a direct answer.
11:44.720 --> 11:50.840
So we're going to break it into parts and look for the PHP Docker image.
11:50.840 --> 11:59.660
And here is the PHP Docker image, which has a tag, which you will find 8.2 Apache.
11:59.660 --> 12:01.840
That should be there, like right there.
12:01.840 --> 12:02.840
That's a tag.
12:02.840 --> 12:06.960
So that's what we are interested in, because that's what the WordPress guys use to begin
12:06.960 --> 12:09.840
their WordPress image creation.
12:09.840 --> 12:13.640
So this happens to be a completely different image that gives you two things already to
12:13.640 --> 12:15.880
begin with.
12:15.880 --> 12:20.360
So you can see the layers and layers and layers of how we are going to go deep all the way
12:20.360 --> 12:29.200
to ground zero, which is nothing, which is also known as scratch, empty space.
12:29.200 --> 12:32.720
We'll reach there soon.
12:32.720 --> 12:37.360
So we began with understanding what WordPress uses to create the WordPress image by looking
12:37.360 --> 12:39.320
at the WordPress Docker file.
12:39.320 --> 12:42.600
And we found out that it begins with this.
12:42.600 --> 12:50.760
If you look at this particular Docker image, we'll have to go and hunt down its Docker file.
12:50.760 --> 12:53.800
And you will see that it contains these two things, PHP and Apache.
12:53.800 --> 12:55.960
So let's go hunt.
12:55.960 --> 12:59.280
Where is the Docker file for this?
12:59.280 --> 13:08.560
And we'll go hunt simply by clicking the link somewhere here to find it.
13:08.560 --> 13:14.760
And so we can just hit on maybe this, not this.
13:14.760 --> 13:21.960
So if you don't find it, just take that code or take that string and look for Docker file
13:21.960 --> 13:26.060
for PHP and that code number 8.2.
13:26.060 --> 13:30.440
And there you will have and also put GitHub.
13:30.440 --> 13:37.840
So you'll find a Docker file reference to that particular PHP image.
13:37.840 --> 13:39.720
There it is, by the way.
13:39.720 --> 13:42.600
So what are you looking at now?
13:42.600 --> 13:48.320
On the left side is the image that we are interested in, which is PHP 8.2.
13:48.320 --> 13:57.480
And on this right side, 8.2 Buster Apache Docker file.
13:57.480 --> 14:05.620
That's the Docker file that was used to create the image on the left side here.
14:05.620 --> 14:09.980
It contains PHP version 8.2 and also includes Apache.
14:09.980 --> 14:16.360
And that's the Docker file that creates this image that WordPress Docker file uses.
14:16.360 --> 14:19.760
It begins with this beginning point.
14:19.760 --> 14:28.340
But this beginning point itself has another beginning point, which is right there.
14:28.340 --> 14:35.880
This image uses another image called Buster Slim, Debian OS.
14:35.880 --> 14:37.960
Debian is a Linux OS.
14:37.960 --> 14:45.460
It uses another image to construct this image.
14:45.460 --> 14:50.200
So we'll go deeper and understand where this thing comes from.
14:50.200 --> 14:52.560
This thing comes from Debian Buster.
14:52.560 --> 14:58.100
So let's go hunt and find out where does Debian Buster comes from.
14:58.100 --> 15:10.580
So we'll go copy this and look at Docker Hub, and then search for Debian Buster Slim.
15:10.580 --> 15:15.240
And you don't find it like that, so just look for Debian alone.
15:15.240 --> 15:17.720
And then you find it.
15:17.720 --> 15:24.600
And then look for the tag reference and search for it, like Buster Slim, and you will find
15:24.600 --> 15:25.600
it there.
15:25.600 --> 15:28.060
So that's the image.
15:28.060 --> 15:32.280
That PHP Apache Docker file uses.
15:32.280 --> 15:34.360
But where is the source code for this?
15:34.360 --> 15:38.200
We go to another hunting on GitHub.
15:38.200 --> 15:39.520
And then I will summarize this whole thing.
15:39.520 --> 15:44.920
We are going down the deep, all the way to the rabbit hole, all the way to ground zero.
15:44.920 --> 15:47.900
That's where we are reaching slowly, step by step.
15:47.900 --> 15:56.040
So we'll go GitHub and look for Debian Buster Docker file.
15:56.040 --> 16:00.720
And here it is, the source code for that.
16:00.720 --> 16:08.200
Library Debian, hold on, let me go full screen.
16:08.200 --> 16:13.840
This is not the Docker file, but we're going to go and look for that particular Docker
16:13.840 --> 16:22.000
file in Debian, which is not readily visible here.
16:22.000 --> 16:30.760
Docker file is in a different location apparently here.
16:30.760 --> 16:36.320
So they give you a link here, somebody else is maintaining it apparently.
16:36.320 --> 16:40.000
So that's the Docker file somewhere, it's just a Docker generator.
16:40.000 --> 16:41.800
So stack-brewed library generator.
16:41.800 --> 16:46.320
So you will see that this is a generator to generator Docker file.
16:46.320 --> 16:52.960
So there's lots of variations here to basically lead to a situation which creates a Docker
16:52.960 --> 16:56.480
file to build a Debian Buster.
16:56.480 --> 17:05.200
And to create a Debian Buster Docker file, we have to begin from literally, let's see
17:05.200 --> 17:10.840
if we can find a separate simple example of how they build Debian images.
17:10.840 --> 17:20.920
Debian Docker file and then scratch.
17:20.920 --> 17:24.120
I'm going to select an alternative example.
17:24.120 --> 17:36.560
How do you create a simple Docker file that contains basically nothing to begin with?
17:36.560 --> 17:41.760
And so that's what I'm trying to hunt.
17:41.760 --> 17:47.040
Not in this page, scratch, and I think this is the beginning point.
17:47.040 --> 17:52.460
This scratch basically contains nothing, Docker pulls scratch.
17:52.460 --> 17:54.560
It has literally nothing.
17:54.560 --> 18:01.120
And then you add the Debian OS artifacts, which is the operating system itself.
18:01.120 --> 18:05.720
So now I will draw a picture and help you understand the whole game.
18:05.720 --> 18:09.840
For that, I need to bring up a sheet of paper.
18:09.840 --> 18:13.040
And here it is.
18:13.040 --> 18:20.040
In this sheet of paper, I will draw a picture of how we begin creating step by step the
18:20.040 --> 18:21.720
things that we need.
18:21.720 --> 18:28.120
At the foundation, we will have nothing also known as scratch.
18:28.120 --> 18:34.840
This is the scratch thing that I mentioned.
18:34.840 --> 18:36.320
That basically means a beginning point.
18:36.320 --> 18:38.000
It has nothing in it.
18:38.000 --> 18:42.120
Then on top, you add the Debian OS.
18:42.120 --> 18:43.720
In our example, we are using Debian.
18:43.720 --> 18:48.160
You can use any OS, the Debian OS artifacts.
18:48.160 --> 18:52.320
By the way, these things are already done for you.
18:52.320 --> 18:55.360
Most of the time, you will not be beginning from here and here.
18:55.360 --> 18:57.920
You will begin at a higher level.
18:57.920 --> 19:01.120
It's easier as we begin working.
19:01.120 --> 19:05.800
I'm showing you the ground-up, bottom-up approach of how people build these things so that you
19:05.800 --> 19:07.120
will understand.
19:07.120 --> 19:09.160
You don't need to start here at all.
19:09.160 --> 19:12.960
This is not your starting point right now.
19:12.960 --> 19:20.080
But the Debian OS artifacts, when these artifacts get added, then you get the Debian image.
19:20.080 --> 19:26.640
Debian image, which you can, you know, version of the operating system here can be Buster
19:26.640 --> 19:29.540
is a code name for Debian.
19:29.540 --> 19:35.800
So that Buster becomes a tag for that image, Debian Buster and the Slim variation.
19:35.800 --> 19:42.440
The smaller, simple variation of Debian Buster Slim is the operating system image that is
19:42.440 --> 19:49.540
added on to scratch, to nothing, to get us a Debian Docker image.
19:49.540 --> 19:57.340
That is used by PHP people, the people who write PHP code, the language, PHP.
19:57.340 --> 20:02.260
And they are using, what, 8.2 version of PHP.
20:02.260 --> 20:10.280
And then they also add Apache, the web server, on top of this ready-made image that you can
20:10.280 --> 20:12.680
just use.
20:12.680 --> 20:20.440
And this image is used by the WordPress people to create WordPress colon latest image.
20:20.440 --> 20:28.680
So if you now see, typically, if you want to go ready-made, you go use this.
20:28.680 --> 20:32.480
You want to customize a little bit, you go one step below.
20:32.480 --> 20:37.080
You want to modify PHP 8.2 and make it 8.1.
20:37.080 --> 20:42.360
You can do that by just changing the image, or you can modify by changing the operator
20:42.360 --> 20:48.160
underlying Docker file itself to get the right version of operating system, the right version
20:48.160 --> 20:53.240
of your PHP language, the right version of Apache, or whatever you need under the hood
20:53.240 --> 20:56.840
is how you begin creating whatever you need.
20:56.840 --> 21:01.120
So Docker file needs to be rewritten.
21:01.120 --> 21:03.560
So that was the example of WordPress.
21:03.560 --> 21:08.720
So this was multiple levels of abstraction beginning from scratch.
21:08.720 --> 21:14.280
Add the operating system, choose a specific version, add a language, choose the language
21:14.280 --> 21:21.080
version, add a web server, then create the application on top to create the WordPress
21:21.080 --> 21:22.080
image.
21:22.080 --> 21:25.160
Lots of detail here involved.
21:25.160 --> 21:26.480
It's a complex application.
21:26.480 --> 21:35.240
I'll simplify it to the simple possible example I will now take, which is let's choose Nginx
21:35.240 --> 21:44.200
as an application, which is a web server.
21:44.200 --> 21:50.820
And we will add this on top of an operating system called Ubuntu, which is built on top
21:50.820 --> 21:55.760
of scratch, basically nothing.
21:55.760 --> 21:59.480
So empty slate, you add Ubuntu operating system.
21:59.480 --> 22:05.080
And then on top, we will add our application Nginx.
22:05.080 --> 22:10.100
And then we'll add something else on top to make it visible to us so we can see what we
22:10.100 --> 22:12.560
are doing and understand it and make use of.
22:12.560 --> 22:19.240
So this is a slightly simple example of what we will be doing actually in a hands-on exercise.
22:19.240 --> 22:25.480
So we'll begin here because I don't want to unnecessarily complicate things by helping
22:25.480 --> 22:29.040
you understand how do you begin from scratch and add the operating system.
22:29.040 --> 22:32.800
That's unnecessarily complicated to begin with as the first thing you do.
22:32.800 --> 22:34.400
So don't do that.
22:34.400 --> 22:40.240
Begin simpler by beginning from Ubuntu and then add Nginx.
22:40.240 --> 22:42.560
So let's go see how you do that.
22:42.560 --> 22:43.920
So we have to get Ubuntu first.
22:43.920 --> 22:45.820
Where do you get Ubuntu?
22:45.820 --> 22:53.600
You get it from Docker Hub, Ubuntu.
22:53.600 --> 22:56.000
There it is.
22:56.000 --> 23:04.480
So that is the place where you can pull Ubuntu image from somebody waiting apparently on
23:04.480 --> 23:05.480
the meeting.
23:05.480 --> 23:11.260
So we let them in and they are coming in.
23:11.260 --> 23:14.600
And so hello, hello.
23:14.600 --> 23:15.600
Somebody just joined.
23:15.600 --> 23:16.600
Hi, Suraj.
23:16.600 --> 23:17.600
Hi.
23:17.600 --> 23:23.520
So we're talking about this thing called using the Ubuntu image as the foundation and add
23:23.520 --> 23:26.000
an application on top.
23:26.000 --> 23:30.400
So what I will now do is Docker pull Ubuntu.
23:30.400 --> 23:35.400
So it brings down the latest version of Ubuntu operating system container image available
23:35.400 --> 23:38.120
to me on my Linux machine.
23:38.120 --> 23:40.000
I now have it.
23:40.000 --> 23:43.840
It just pulled a Docker image.
23:43.840 --> 23:45.560
So now I have that image.
23:45.560 --> 23:51.400
What I want to be able to do now is to create a Docker file that uses that image.
23:51.400 --> 23:53.680
How do you create that?
23:53.680 --> 23:58.640
Simply you start a.
23:58.640 --> 24:03.760
A empty file and start typing in the beginning point.
24:03.760 --> 24:06.880
Beginning point happens to be in our case Ubuntu.
24:06.880 --> 24:11.140
So what I want to do is go to that Linux machine.
24:11.140 --> 24:16.440
So I will go to that Linux machine called iMac and hit that button.
24:16.440 --> 24:19.800
So I enter that machine remotely.
24:19.800 --> 24:25.720
And there I will create a separate folder for us to play with.
24:25.720 --> 24:28.680
And in there I will create a separate folder.
24:28.680 --> 24:29.680
Let's call it.
24:29.680 --> 24:31.320
What do you want to call today?
24:31.320 --> 24:34.840
So let's let's create a new folder.
24:34.840 --> 24:37.960
And we'll call it.
24:37.960 --> 24:40.760
Docker test.
24:40.760 --> 24:44.200
And in that folder will create a new file.
24:44.200 --> 24:47.320
I'll call it Docker file.
24:47.320 --> 24:48.560
And it's an empty file.
24:48.560 --> 24:51.640
I want to begin from Ubuntu.
24:51.640 --> 24:52.840
That's my beginning point.
24:52.840 --> 24:53.840
That's it.
24:53.840 --> 24:54.840
That's my Docker file.
24:54.840 --> 24:57.720
It's a complete Docker file, by the way, so close it.
24:57.720 --> 25:00.200
I can see it again and it's there.
25:00.200 --> 25:05.840
I can now go back here in the machine and say CD Docker test.
25:05.840 --> 25:08.440
And there I will find the Docker file that I created.
25:08.440 --> 25:10.440
I can see and inspect it.
25:10.440 --> 25:14.960
And I see that it has the content that I created.
25:14.960 --> 25:17.880
It says from Ubuntu.
25:17.880 --> 25:19.500
That's the beginning point.
25:19.500 --> 25:21.600
So now I have the Docker file created.
25:21.600 --> 25:26.120
It has one line, which is this line from Ubuntu.
25:26.120 --> 25:28.840
And I want to create a Docker image using that.
25:28.840 --> 25:30.440
How do you do that?
25:30.440 --> 25:33.280
The Docker build.
25:33.280 --> 25:37.280
And then put a dot.
25:37.280 --> 25:43.560
The dot basically means a reference to location where the Docker file exists.
25:43.560 --> 25:48.040
The Docker file exists in this location right here.
25:48.040 --> 25:53.320
And so I want to say Docker build whatever you have in this folder.
25:53.320 --> 25:55.720
The dot means right here.
25:55.720 --> 25:59.480
So it builds and it builds successfully.
25:59.480 --> 26:02.720
It was easy for it to build because there was nothing much to do.
26:02.720 --> 26:05.900
Just use an existing image called Ubuntu.
26:05.900 --> 26:06.900
So it builds.
26:06.900 --> 26:10.120
Now we have a new image created already.
26:10.120 --> 26:12.520
We can even run it if you like.
26:12.520 --> 26:18.060
But it is the same thing as running our own image as same thing as running Ubuntu image.
26:18.060 --> 26:23.680
So we have the images that we created right now like that.
26:23.680 --> 26:29.520
We can give it a name, a specific name I want to give, like this, dash T, and call it Docker
26:29.520 --> 26:30.520
test.
26:30.520 --> 26:32.560
That's the name I want to give.
26:32.560 --> 26:40.360
But a proper way to name is not just the name, but a place to store the image eventually,
26:40.360 --> 26:45.560
like a library where you can push your images and store them, for example, Docker Hub.
26:45.560 --> 26:50.800
So Docker Hub has a name of, let's go see what names that these guys use.
26:50.800 --> 26:55.800
So every company that provides you a place to store images will have a name, a way to
26:55.800 --> 26:58.040
represent that name.
26:58.040 --> 27:03.560
And so these guys have a name called Docker pull Ubuntu, but the right way to say that
27:03.560 --> 27:07.960
is actually Docker dot IO library reference.
27:07.960 --> 27:14.080
I'm forgetting what the name reference is.
27:14.080 --> 27:21.520
So I'm going to search it container name reference, and that should show us the pull reference
27:21.520 --> 27:26.160
as to how you write the name of an image.
27:26.160 --> 27:36.400
So the way to write an example Docker image when you pull from Docker Hub is just the
27:36.400 --> 27:41.400
name library Debian or library Ubuntu.
27:41.400 --> 27:47.600
And when you pull from other locations, it is not clear as to which location are you
27:47.600 --> 27:49.400
coming from.
27:49.400 --> 27:54.600
So just like Docker Hub, there are other places to store container registry images, and those
27:54.600 --> 28:05.240
are Azure Container Registry, not this ACR, but Azure.
28:05.240 --> 28:08.540
So Azure Container Registry is right there.
28:08.540 --> 28:12.800
And so here you can also find certain images available.
28:12.800 --> 28:17.600
Similar to that, there is this Amazon Container Registry from Amazon Cloud.
28:17.600 --> 28:21.720
They provide you a place to store images just like Docker Hub does.
28:21.720 --> 28:25.160
Similar to that, there is Google Container Registry from Google.
28:25.160 --> 28:28.560
And they also provide a place to store images like this.
28:28.560 --> 28:34.440
So lots of people, lots of companies provide you a place to store images.
28:34.440 --> 28:40.920
And my company, I have my own place to store images, and that thing is simply this location.
28:40.920 --> 28:47.600
I do not show you anything because it is actually accessible through an API call.
28:47.600 --> 28:49.080
And you have to log in and so on.
28:49.080 --> 29:05.520
Let me see if I can log in.
29:05.520 --> 29:13.800
Yes, I logged in.
29:13.800 --> 29:20.440
And here are some images that I have stored in my own local registry.
29:20.440 --> 29:26.280
So I can push my image that I create into this registry that I hold in my company.
29:26.280 --> 29:33.520
That's just my own registry, very, very similar to these guys, or these guys, or these guys.
29:33.520 --> 29:36.040
It looks different, but functions the same way.
29:36.040 --> 29:40.720
This is mine, like hosted in my company.
29:40.720 --> 29:49.440
So an example of this thing called Photo Prism is an image that I have pushed to my registry.
29:49.440 --> 29:53.680
And the way I reference my registry is with the name that I have given it.
29:53.680 --> 30:04.120
And the name that I chose to give my registry is simply the URL that you go to.
30:04.120 --> 30:15.540
This is the name of my registry.
30:15.540 --> 30:35.120
And so the way I recommend naming my employees to use a Docker image name is like this.
30:35.120 --> 30:47.640
So for example, we can use something like reg.home.cloudgenie.us.
30:47.640 --> 30:51.400
And you can call it Ubuntu test, like that.
30:51.400 --> 30:57.320
So that's the proper way to name an image that you want to store in a registry location
30:57.320 --> 30:59.540
provided to you by some company.
30:59.540 --> 31:03.040
You can run your own registry, like I run myself.
31:03.040 --> 31:06.680
So this is a way, we'll talk about how to create your own registry later on, not right
31:06.680 --> 31:07.840
now.
31:07.840 --> 31:10.960
But this is my registry, here is how you name it.
31:10.960 --> 31:17.080
So if you have a thing stored in Google Cloud, it is something like this, gcr.io slash and
31:17.080 --> 31:23.520
some other names that Google will dictate, followed by Ubuntu test.
31:23.520 --> 31:26.640
That's how you will store it in Google Cloud.
31:26.640 --> 31:32.960
In Azure Cloud, it will be very similar, followed by some name that Azure will want you to use.
31:32.960 --> 31:41.840
And then your name of the image in Elastic Cloud from Amazon, it will be ECR.
31:41.840 --> 31:46.400
So various companies will have their own naming conventions, you need to follow their conventions.
31:46.400 --> 31:51.760
I will follow my company's conventions, which is line number four.
31:51.760 --> 31:56.400
If you don't follow any convention that is also legally acceptable, you can just go with
31:56.400 --> 31:58.040
line number one.
31:58.040 --> 32:00.680
I will choose line number three.
32:00.680 --> 32:07.360
I will choose that and actually go to my command line and give that name to my image and build
32:07.360 --> 32:10.300
that same image one more time.
32:10.300 --> 32:12.240
And here it goes, it builds.
32:12.240 --> 32:18.840
It also assigns it a name like that, what I chose.
32:18.840 --> 32:24.240
And what I can do now is push this image to my own registry, I created a new image, you
32:24.240 --> 32:30.260
can see it, it did create, let's go see Docker images and then look for the name and it shows
32:30.260 --> 32:36.400
up created and then I will now talk or push this image.
32:36.400 --> 32:44.520
So it goes to my registry in my home and it did and it succeeded.
32:44.520 --> 32:52.640
Let's go back to that website and here you don't see Ubuntu test yet, but when I refresh,
32:52.640 --> 32:55.000
you see it.
32:55.000 --> 32:59.240
So that is how I push images to a registry.
32:59.240 --> 33:06.720
Same exact method, you can push it to this cloud, this Google cloud or to this cloud,
33:06.720 --> 33:10.800
Amazon cloud or to this cloud, Azure cloud or to some other cloud, who knows what.
33:10.800 --> 33:14.640
It doesn't matter, anybody and everybody can bring in their own registry.
33:14.640 --> 33:18.640
So I bring my own homemade registry and I pushed it.
33:18.640 --> 33:21.880
Once I have it in my registry, I can pull it from there and push it to there and do
33:21.880 --> 33:22.880
whatever I want.
33:22.880 --> 33:23.880
But that's an image.
33:23.880 --> 33:24.880
I can consume it.
33:24.880 --> 33:26.660
I have assigned it a name.
33:26.660 --> 33:35.160
My name is line number three.
33:35.160 --> 33:39.160
I will ignore line number five, six, seven, eight, all that.
33:39.160 --> 33:42.880
And that number one is a simple name to the same thing.
33:42.880 --> 33:56.360
I build it using this instruction in line number two.
33:56.360 --> 34:12.800
You can also build the same thing without a name at all.
34:12.800 --> 34:13.800
Just like that.
34:13.800 --> 34:17.920
Or you can build it with a simple name like that.
34:17.920 --> 34:23.240
There is the same thing, except if you properly name it like line number one, you can push
34:23.240 --> 34:28.440
it and pull from by using these commands, dot or push.
34:28.440 --> 34:33.120
And then give it a reference name to the exact fully qualified name of the image.
34:33.120 --> 34:34.120
And it pushes.
34:34.120 --> 34:38.720
You want to pull, it pulls from that location that you have.
34:38.720 --> 34:43.280
And of course, it requires login name and password and some permission because I don't
34:43.280 --> 34:47.480
allow anybody and everybody to be able to push and pull from my home.
34:47.480 --> 34:51.840
It is my property and I don't allow other people to consume it.
34:51.840 --> 34:55.640
So line seven and eight requires permission from me.
34:55.640 --> 35:05.540
Similarly, these guys, they require permission from you, require permission from them.
35:05.540 --> 35:08.940
And same thing with this guy, Docker Hub.
35:08.940 --> 35:12.640
They also need you to log in and put some.
35:12.640 --> 35:15.680
I think most of it is free, but sometimes they charge you money.
35:15.680 --> 35:18.160
So we do sometimes need a credit card.
35:18.160 --> 35:20.600
Most of it is free, by the way, as you begin learning.
35:20.600 --> 35:23.000
So it's not a problem at all.
35:23.000 --> 35:26.900
However, we have created an image and we pushed it.
35:26.900 --> 35:30.400
Now let us see if you can run that image.
35:30.400 --> 35:31.840
How do you run an image?
35:31.840 --> 35:38.640
You simply go like this.
35:38.640 --> 35:44.160
Here and say.
35:44.160 --> 35:52.120
Docker run an image interactively and put in an image name like line number 13 is the
35:52.120 --> 35:54.880
name of my image.
35:54.880 --> 35:57.040
And then give me a badge prompt.
35:57.040 --> 36:01.400
So that's the command you want to be able to run to execute to run that container that
36:01.400 --> 36:03.920
you just created.
36:03.920 --> 36:07.160
So we use this Docker file.
36:07.160 --> 36:14.240
And command in line number one to build the image command in line number seven to push
36:14.240 --> 36:16.020
the image.
36:16.020 --> 36:20.880
And then command in line number 17 to run the image.
36:20.880 --> 36:22.880
Here's how it runs.
36:22.880 --> 36:25.480
Sorry, I didn't copy properly.
36:25.480 --> 36:27.840
Here's how it runs.
36:27.840 --> 36:30.860
It is running now.
36:30.860 --> 36:37.640
You can see that the version number of this particular Linux, the kernel version is 515,
36:37.640 --> 36:40.480
which is the same thing as the kernel I have.
36:40.480 --> 36:58.400
You can see that this version is also hold on.
36:58.400 --> 37:02.900
Let's put something in this container for us to make use of it in a in a slightly better
37:02.900 --> 37:03.900
fashion.
37:03.900 --> 37:11.980
Let's go back to the notes here and what I have done up till now, sorry.
37:11.980 --> 37:18.120
In this context, what I have done up till now is that I was able to use the Ubuntu image
37:18.120 --> 37:23.240
and create my own Docker file to create my own image, which is basically identical to
37:23.240 --> 37:26.200
the Ubuntu image because I haven't even modified anything.
37:26.200 --> 37:36.440
The next thing I want to be able to do is add nginx to my basic foundation of Ubuntu
37:36.440 --> 37:42.160
for which I need to add a line to my Docker file and I will do that right now.
37:42.160 --> 37:52.280
So I will go back to my Docker file and here I will say add nginx in the way you add in
37:52.280 --> 38:09.400
a Ubuntu image is you need to first of all run apt update and then run apt install nginx.
38:09.400 --> 38:13.360
That's how you run it in a actual Ubuntu machine.
38:13.360 --> 38:17.800
So in a Docker file context, you add the run commands in line number two and three to make
38:17.800 --> 38:19.460
things happen.
38:19.460 --> 38:24.880
Now I have expanded my Docker file, added two layers to it to create nine line number
38:24.880 --> 38:29.520
two and line number three, and I will use this Docker file to build my own image one
38:29.520 --> 38:30.520
more time.
38:30.520 --> 38:33.040
How do I build my image?
38:33.040 --> 38:34.040
Line number one.
38:34.040 --> 38:44.160
So I take that and execute in my command line, exit out of my container, go back to check
38:44.160 --> 38:49.800
my Docker file and I see that it has now three lines as opposed to one, I added these two
38:49.800 --> 38:57.760
things to the Ubuntu basic foundation and then I build my image one more time.
38:57.760 --> 39:01.080
You will see this time the Docker building process is actually doing the two things,
39:01.080 --> 39:05.440
line number two and line number three again for us, like this is the line happening and
39:05.440 --> 39:06.720
then this is happening.
39:06.720 --> 39:11.240
You can see that the nginx installation is happening right now.
39:11.240 --> 39:15.980
When this finishes, you will have a new image created, which is our own customized image
39:15.980 --> 39:21.640
called reg home cloud genius went to test.
39:21.640 --> 39:26.360
That created a new image for us because that's what we wanted.
39:26.360 --> 39:32.260
We wanted a new custom Docker image containing nginx.
39:32.260 --> 39:35.100
So we now have it.
39:35.100 --> 39:39.360
How do we make sure that it actually does have what we wanted it to have?
39:39.360 --> 39:48.120
We can do that by running that image again this time, same way like before, Docker run
39:48.120 --> 39:50.480
and there we have that Ubuntu image running again.
39:50.480 --> 39:59.240
But this time if you see it has nginx running or not running yet, is it not running?
39:59.240 --> 40:14.720
Hold on, let's check it should be running.
40:14.720 --> 40:15.720
Now we have to run it.
40:15.720 --> 40:17.640
We have to actually, this is just installed.
40:17.640 --> 40:24.040
So there is nginx installed, we haven't run it yet, so we have to run it.
40:24.040 --> 40:28.840
The way to execute that I think is cmd and then you have to pass some argument like say
40:28.840 --> 40:30.680
run nginx please or something like that.
40:30.680 --> 40:35.720
We're going to do some command like line number five shows in our Docker file for the nginx
40:35.720 --> 40:38.280
binary to execute.
40:38.280 --> 40:42.960
And that's what I will have to investigate as to what do we write here exactly to get
40:42.960 --> 40:47.940
nginx to run after you install it in line number three.
40:47.940 --> 40:53.240
What is it that is needed for nginx to run at the runtime when you run this image?
40:53.240 --> 40:55.760
And for that we have to go reference the documentation.
40:55.760 --> 40:59.100
So that's the best way to learn is to read the documentation.
40:59.100 --> 41:04.560
So let's go find out how do you run something in a Docker image.
41:04.560 --> 41:13.000
You simply go Docker file run command.
41:13.000 --> 41:19.840
And you hunt for it and you will find the Docker reference to it.
41:19.840 --> 41:24.960
And here are some examples of run echo something.
41:24.960 --> 41:27.620
Run echo hello world example.
41:27.620 --> 41:42.680
So we'll go look for a specific example of run nginx.
41:42.680 --> 41:48.760
And you will see that people may have given you instructions on how do you do this so.
41:48.760 --> 41:54.720
You can we can copy paste or cheat cheating is totally fine and it's a it's a great idea
41:54.720 --> 41:58.680
to look at what other people are doing and then do what you want to be able to do.
41:58.680 --> 42:00.220
And so I support cheating.
42:00.220 --> 42:03.520
I actually support everything open.
42:03.520 --> 42:07.440
And you know the whole Internet available to you and you know chat GPT available to
42:07.440 --> 42:12.440
you and fully cheat to make it easy for you to get things done.
42:12.440 --> 42:28.280
And so here let's go see if they have a Docker file example or that that they're cheating
42:28.280 --> 42:30.520
even further and using a readymade nginx image.
42:30.520 --> 42:33.520
So not this.
42:33.520 --> 42:42.080
Yeah, these guys should have it.
42:42.080 --> 42:43.720
And there it is.
42:43.720 --> 42:52.240
So the command is this to run nginx at the runtime without a daemon so it doesn't have
42:52.240 --> 42:57.560
to run by itself but only run when you run it the run it in the Docker way.
42:57.560 --> 43:03.880
So this line number five that you see is actually going to invoke nginx at the runtime when
43:03.880 --> 43:06.840
you invoke that particular Docker image.
43:06.840 --> 43:11.000
Since we added this new command in line number four in the Docker file we need to build our
43:11.000 --> 43:16.040
container image one more time using line number one.
43:16.040 --> 43:21.760
So I'll copy that line number one again go back to my command line exit out of the existing
43:21.760 --> 43:30.120
container and run the build instruction one more time so it builds then we'll run it how
43:30.120 --> 43:37.220
do you run like line number 17 we'll copy that and run it here and it runs something
43:37.220 --> 43:44.200
let us go see what is running right now and you still don't see anything running in nginx
43:44.200 --> 43:50.560
because we are not invoking it let's go let's go run it in a different fashion.
43:50.560 --> 43:58.120
So I'm going to exit this and describe the different fashion of running this Docker run
43:58.120 --> 44:06.400
in a daemon mode the same image like before but not run it like interactively instead
44:06.400 --> 44:10.760
run it like a daemon in the background and then we'll go and examine as to what it is
44:10.760 --> 44:17.000
doing so let us see if this thing gets us the result we want so it started some container
44:17.000 --> 44:29.840
let us examine what is running by Docker ps-a and then looking for Ubuntu test and we see
44:29.840 --> 44:36.960
that something is actually running like right there 15 seconds ago up and running for last
44:36.960 --> 44:44.440
14 seconds something is running that is nice and so we will go and examine what is running
44:44.440 --> 44:51.760
by entering the container from outside for which we need to grab the image ID sorry it's
44:51.760 --> 45:00.240
a container at runtime ID this number 505 and execute into that and get a bash prompt
45:00.240 --> 45:05.120
and there you check the process is running and you will see nginx is running that's a
45:05.120 --> 45:11.320
good sign now let us see if you can actually open a website and a browser to see what is
45:11.320 --> 45:16.880
running in that container for that I would like you to understand what we did the last
45:16.880 --> 45:24.680
time clearly and so let's summarize what we have done up till now what we have done up
45:24.680 --> 45:35.280
till now is we have modified our Dockerfile to not only add nginx but also run nginx by
45:35.280 --> 45:42.080
typing in a cmd in the Dockerfile cmd run command we added on that thing and then we
45:42.080 --> 45:48.480
ran this we built this entire image and then we ran it it seems to run but I want to feel
45:48.480 --> 45:55.800
happy by seeing it visually in a browser that is possible but you need to work towards it
45:55.800 --> 46:05.920
what does it mean it means we have in a Docker container running nginx on port number 80
46:05.920 --> 46:15.160
inside the container on a machine which is the imac that I talk about but this port number
46:15.160 --> 46:21.320
80 is not visible to us outside so we need to do a port mapping if you refer to the previous
46:21.320 --> 46:26.360
meeting like the week ago I think I described this concept clearly but I will do it again
46:26.360 --> 46:35.600
simply I want to be able to map this port number 80 to the imac port of some number
46:35.600 --> 46:41.720
like I need to map this number 80 to some port here on the imac so that I can see what
46:41.720 --> 46:49.120
is going on here so on this machine we need to look up ports that are available in open
46:49.120 --> 46:58.020
so one of the ports that I have available in open is 8760 that I like to use there are
46:58.020 --> 47:02.760
other things you can use like 80 is also sometimes available in most cases you can use that port
47:02.760 --> 47:07.700
if you're like on a new machine or an empty new fresh new cloud you can use that but I
47:07.700 --> 47:12.960
have my machines already occupied the port is taken I cannot use this so I have to map
47:12.960 --> 47:19.440
a different port to this port inside the container so this port mapping thing I think I discussed
47:19.440 --> 47:25.480
in a previous session you should go look at that if you are missing that concept but the
47:25.480 --> 47:34.360
idea will be to use that concept of port mapping like we did the last time by expanding this
47:34.360 --> 47:42.360
line number 20 and making it a new line 22 out of it and including the port mapping like
47:42.360 --> 47:55.400
that map it to 80 that's all that's all it takes what does this do what it does is exactly
47:55.400 --> 48:04.280
what we wanted which is map port number 80 in the container to port number 8760 on the
48:04.280 --> 48:18.320
iMac rest of it is all the same I inserted this portion in the command sequence to let
48:18.320 --> 48:26.240
the port mapping succeed and when you see that and run it like line number 22 you should
48:26.240 --> 48:32.480
be able to see what that nginx container is showing you by visiting the iMac on port number
48:32.480 --> 48:39.920
8760 you can modify your ports the way you like if you want to have a discussion on what
48:39.920 --> 48:43.360
these ports are you should refer to the previous meeting because we discussed these things
48:43.360 --> 48:51.920
last time so let us go line number 22 and run that but before that we have to kill what
48:51.920 --> 49:00.440
we did in line number 20 and so that's what I will do now and I will open up my terminal
49:00.440 --> 49:08.880
and kill this docker container that is already running there and that is this number 505
49:08.880 --> 49:19.800
I will say docker rm-f and the number is 505 so it dies then I will also check any docker
49:19.800 --> 49:33.760
processes running in my machine with the name docker test and there is none nothing is there
49:33.760 --> 49:40.120
that is running right now so now our machine is clear for us to run this command in line
49:40.120 --> 49:49.440
number 22 which is what we just discussed so I will copy that 22 bring it here run it
49:49.440 --> 49:56.600
and it runs so now you can see that there is this docker container running oh so docker
49:56.600 --> 50:06.280
test is ubuntu test what am I talking about okay there it is now it is running again and
50:06.280 --> 50:14.320
that is what we just started so let us go examine what did we just start and why is
50:14.320 --> 50:19.360
it you know working the way it is so let's go first of all read and understand what did
50:19.360 --> 50:29.200
we start and how it shows in our result in docker ps-a and then grab for ubuntu test
50:29.200 --> 50:38.720
and there it is so let us go see what it shows us examine here is the image id sorry image
50:38.720 --> 50:44.680
container runtime reference here is the image name that we chose it is running the nginx
50:44.680 --> 50:52.160
in daemon off and it is up and running for last 39 seconds and it has this port mapping
50:52.160 --> 51:01.600
that I wanted on the imac map to the container port number 80 so that mapping seems to be
51:01.600 --> 51:09.120
successfully showing which means if you visit the imac on that port number 8760 you should
51:09.120 --> 51:15.800
see what the nginx container is showing you inside on port number 80 that is a port mapping
51:15.800 --> 51:30.000
so now let us go visit the imac on port number 8760 and we should be greeted by a nginx response
51:30.000 --> 51:39.040
so here is your imac and the port number 8760 and you see nginx now I can prove to you that
51:39.040 --> 51:50.920
I am not cheating by looking at that docker image and killing it
51:50.920 --> 52:02.480
so I killed it and I will examine that there is nothing running in my computer containing
52:02.480 --> 52:08.880
the name ubuntu test is empty it's all dead you can see that in this browser window if
52:08.880 --> 52:16.040
I refresh unable to connect I go back here to the command line and run that same line
52:16.040 --> 52:23.320
number 22 one more time this is your line number 22 for you like right here same line
52:23.320 --> 52:32.640
number 22 I run it in the command line like that then I go to the browser and refresh
52:32.640 --> 52:38.680
and it shows back up so that is how you build a docker image and run some application in
52:38.680 --> 52:45.660
the simplest fashion very simply let us summarize what do we do questions by the way are welcome
52:45.660 --> 52:50.800
anytime you have a question you should ask that if you don't ask questions it is bad
52:50.800 --> 52:55.720
really bad you know I don't know whether you understanding or not or whether I am talking
52:55.720 --> 53:00.360
to myself so that is something that I want to avoid so you should keep it interactive
53:00.360 --> 53:12.400
okay so now I will draw the picture again and see what we did so what do we do we began
53:12.400 --> 53:28.560
with we began with ubuntu and we chose that as a foundation from then we installed
53:28.560 --> 53:44.920
apt-get update to update the system cache for apt to be able to pull other applications
53:44.920 --> 53:57.500
then we get the application we want apt-get install nginx that actually installs nginx
53:57.500 --> 54:02.360
and this dash y means shut up and install don't ask me questions should I install yes
54:02.360 --> 54:12.000
or no don't do that shut up install that's the idea shut up and install the next thing
54:12.000 --> 54:24.120
we actually execute cmd nginx in some detail about how exactly you write it so that you
54:24.120 --> 54:30.160
look up the documentation or copy paste or cheat but this is how you do it how do you
54:30.160 --> 54:46.320
do it like that line number 4 cmd nginx dash g and then daemon off that basically means
54:46.320 --> 54:58.480
don't run nginx in daemon run it in foreground but invoke once you start this container so
54:58.480 --> 55:04.720
that's the idea so you install this is bring the update update the app cache install nginx
55:04.720 --> 55:11.200
application and run the actual application when the container runs and you begin from
55:11.200 --> 55:17.440
a one two that's how you build docker images of course you can keep on adding complexity
55:17.440 --> 55:21.760
and you guys you have seen like as we started you have seen bigger docker files you will
55:21.760 --> 55:25.900
get there you will get there but you have to understand basics first before you jump
55:25.900 --> 55:37.840
into a complex example so that's the underlying idea questions are welcome go ahead the cmd
55:37.840 --> 55:44.840
portion yes i will do that so you know if you remember how did i find this out i did
55:44.840 --> 55:53.120
not remember what did i do i cheated how did i cheat i google searched let's go where where
55:53.120 --> 56:00.880
did i go i went to the nginx official company's documentation and found out how they are running
56:00.880 --> 56:10.800
it how they are building their docker files for nginx so if you see here on this nginx
56:10.800 --> 56:19.440
company website there is this reference which i copied from right so now let us go see what
56:19.440 --> 56:29.880
they are doing on this page it basically describing to you how to run nginx plus which is a different
56:29.880 --> 56:36.400
application not exactly nginx nginx plus is an enhanced version of nginx commercial version
56:36.400 --> 56:41.160
from the nginx company we are not interested in the nginx plus piece we are interested
56:41.160 --> 56:47.960
only nginx and these guys describe to you how to invoke it so i cheated and what did
56:47.960 --> 56:53.480
i do i looked at their command to execute it it's basically the same command you would
56:53.480 --> 56:59.920
otherwise run if you're running plain nginx and not nginx plus so now let us dissect what
56:59.920 --> 57:11.760
this command actually does nginx you can run it without these guys it will also work however
57:11.760 --> 57:22.600
it goes in demon mode and it keeps on running we don't want that so we disable demon mode
57:22.600 --> 57:32.480
that's the idea nothing else and you if you if you eliminate this and just keep the closing
57:32.480 --> 57:45.080
bracket that is also okay so simply the cmd idea is to invoke or execute this thing at
57:45.080 --> 57:52.480
run time when you run this image not when you build it but when you run it so that's
57:52.480 --> 58:02.360
the difference in between this thing when you have the run steps these are build time
58:02.360 --> 58:11.640
build time executions when you have the cmd step it does nothing at build time except
58:11.640 --> 58:19.560
making a node that when you run it that's what needs to happen so build time you will
58:19.560 --> 58:25.240
actually install this and install that and do this and do that but number four is simply
58:25.240 --> 58:36.640
a way for the image to know what to do when you run it at the run time not at the build
58:36.640 --> 58:42.400
time so when you build the image this basically does nothing except make a note that when
58:42.400 --> 58:55.280
you run this image run engine x in demon off that's it there's nothing more to it does
58:55.280 --> 59:20.040
that clarify but yeah go ahead thank you thank you thank you okay so now let us expand
59:20.040 --> 59:27.320
it a little bit further like slightly improved version of the same thing you know but what
59:27.320 --> 59:40.140
you saw here is what you see in this page when I run that thing you see nginx right
59:40.140 --> 59:53.120
what I want to see here is not what nginx gives me by default but I want to see priti's
59:53.120 --> 01:00:06.200
name showing up how do you do that not what nginx gives me but priti so you have to tell
01:00:06.200 --> 01:00:12.000
your docker image to you know modify something somewhere so that when you open that browser
01:00:12.000 --> 01:00:16.200
it should say hello priti or welcome priti or something like that right that's what
01:00:16.200 --> 01:00:28.600
I want to see so we need to create something we need to go back to our docker file and
01:00:28.600 --> 01:00:38.720
in the docker file you to modify things like what like here somewhere you say you to add
01:00:38.720 --> 01:00:55.200
a file that replaces the default and which file not any file but add a file containing
01:00:55.200 --> 01:01:05.000
the name priti so you add a priti file that replaces the default file that's what we have
01:01:05.000 --> 01:01:13.760
to do so this priti file doesn't exist so you have to create it so we create that like
01:01:13.760 --> 01:01:28.600
this there we go that's a file and I will put that in my computer in that same folder
01:01:28.600 --> 01:01:36.520
by this name index html so that's the file that I created now I have that file so I need
01:01:36.520 --> 01:01:44.680
to add that file priti file it's called index html into a location to replace the default
01:01:44.680 --> 01:01:54.720
right that's what I want to be able to do so how do I do it that's the next thing so
01:01:54.720 --> 01:02:01.520
we have to somehow get this file inside in that location where the default is and delete
01:02:01.520 --> 01:02:09.800
the override delete the old file that exists inside and put this new index html right on
01:02:09.800 --> 01:02:16.720
top of that location you can do it multiple different ways the simplest way is to not
01:02:16.720 --> 01:02:22.360
modify a docker file but pass a file reference from the outside so if you have attended the
01:02:22.360 --> 01:02:28.840
previous sessions you probably know how to map a file if you don't remember I can show
01:02:28.840 --> 01:02:34.160
you both both examples but I will go and give you the cheating example first like how do
01:02:34.160 --> 01:02:43.000
you cheat if you don't know what to do so what do you do you go back to a browser window
01:02:43.000 --> 01:02:51.200
and in there you open up firefox and say add a file to docker file so somewhere there'd
01:02:51.200 --> 01:02:57.480
be how do you add a file to an image so there it is injecting files into your image using
01:02:57.480 --> 01:03:04.120
add so there is an instruction we'll cheat and see what the what the image says so here
01:03:04.120 --> 01:03:16.280
is the usage example we'll just copy it and bring it to our docker file like that here
01:03:16.280 --> 01:03:30.120
if we don't have hello.py we have index.html and we don't have a location where this file
01:03:30.120 --> 01:03:41.720
needs to go so where would it go I don't know so what do you do you cheat again and you
01:03:41.720 --> 01:03:56.360
go and ask where does the nginx image store the default index and the answer is here somewhere
01:03:56.360 --> 01:04:00.200
and so you will read this documentation and you will find out that the location happens
01:04:00.200 --> 01:04:10.960
to be this and I just remember it so I just wrote it but you don't have to memorize anything
01:04:10.960 --> 01:04:16.080
you can always cheat you have google you have the entire internet available to you and you
01:04:16.080 --> 01:04:20.760
these days you have ai tools available to you so use all of them to hunt down the thing
01:04:20.760 --> 01:04:28.280
you need don't memorize anything ever I happen to remember it so that's the location where
01:04:28.280 --> 01:04:35.720
it needs to go so I'll put this index.html file this file hello Preeti into that location
01:04:35.720 --> 01:04:45.280
where it's supposed to be overriding the old location which shows us what we see when you
01:04:45.280 --> 01:05:03.760
go here so now we'll go and build our docker image one more time line number 22 once again
01:05:03.760 --> 01:05:09.360
and so before we go I want to kill the existing container images that I have from a previous
01:05:09.360 --> 01:05:33.720
attempt so I look it up we want to test and I find it I am going to kill it
01:05:33.720 --> 01:05:40.160
and I killed it so now I have nothing running by that name open to test then I will go to
01:05:40.160 --> 01:05:47.320
this line number 22 again and run it so now we have something running again and I will
01:05:47.320 --> 01:05:59.440
go back to this browser and refresh and what do you see you still see the old nginx image
01:05:59.440 --> 01:06:10.080
the old nginx index html why is that why is it that is still showing you old one any ideas
01:06:10.080 --> 01:06:17.480
do you know why because browsers cache everything that they saw so we have to open a different
01:06:17.480 --> 01:06:23.040
browser to see what's going on there there's the there's the reason I think it's it's probably
01:06:23.040 --> 01:06:27.160
caching or maybe there's some other reason so it's not caching it's something else happening
01:06:27.160 --> 01:06:32.720
so let's go investigate if we actually correctly place the file in the right location which
01:06:32.720 --> 01:06:40.800
means we have to go inside this image and actually examine if the location is correct
01:06:40.800 --> 01:06:47.200
that I mentioned that I assumed going by my memory line number four is that actually correct
01:06:47.200 --> 01:06:52.760
user share nginx html is that the correct location that's what I want to examine so
01:06:52.760 --> 01:07:01.960
I'll go inside the image and examine it by running an execute command dr exec and then
01:07:01.960 --> 01:07:08.400
the number 7c1 which you see here in the image id that is the container id that's running
01:07:08.400 --> 01:07:17.240
right now and then getting a bash prompt then we will go and examine the user share nginx
01:07:17.240 --> 01:07:23.240
html folder and there you have this index html and we have to examine what it contains
01:07:23.240 --> 01:07:32.140
and it still has the old file it did not overwrite why did it not overwrite I don't know it should
01:07:32.140 --> 01:07:37.480
have overwritten that but it didn't so we have to go and investigate what went wrong
01:07:37.480 --> 01:07:48.520
something went wrong somewhere so we'll go back to our code and find out why did this
01:07:48.520 --> 01:07:55.320
line number four did not get executed did I forget to build an image probably probably
01:07:55.320 --> 01:08:02.280
I forgot to build the image I don't know so I will go in first of all look at my runtime
01:08:02.280 --> 01:08:12.080
images containing the name ubuntu test and then I will delete that image so now I have
01:08:12.080 --> 01:08:18.680
nothing then I will build the docker image one more time but before I build it I want
01:08:18.680 --> 01:08:29.800
to kill my existing image so docker images that I have and then I will like to remove
01:08:29.800 --> 01:08:34.800
the image that I created at the last time so rmi-f and then the image name what's my
01:08:34.800 --> 01:08:44.240
image name here so I will remove that image by saying docker rmi and then line number
01:08:44.240 --> 01:08:54.000
24 should delete the image completely from my computer like that and it deleted and then
01:08:54.000 --> 01:09:09.760
I will want to build the image one more time like line number 22 and it built so I will
01:09:09.760 --> 01:09:16.880
like to now run it and how do I run it no I did not build it see I am not building I
01:09:16.880 --> 01:09:23.680
am running it I am not building stupid me line number one is how you build it not 22
01:09:23.680 --> 01:09:29.040
number one is how you build it now I built it I think I forgot to build the image I
01:09:29.040 --> 01:09:38.360
just ran line number 22 without actually building it so now I run it and it is running let us
01:09:38.360 --> 01:09:44.680
go inside the image by the way these commands that I type without describing to you you
01:09:44.680 --> 01:09:50.120
should go look at docker documentation and find out how am I dealing with these things
01:09:50.120 --> 01:09:56.600
you should go study it on your own I will like to go inside that container and get a
01:09:56.600 --> 01:10:04.320
bash prompt then get into the user share nginx location go to html location find out the
01:10:04.320 --> 01:10:10.640
file called index html and cat it and we should see hello prithi there there it is nice so
01:10:10.640 --> 01:10:21.960
now I go to the browser and refresh and it is still showing me that is fun is not it
01:10:21.960 --> 01:10:30.800
so let us go check one more time still showing me same old setup even though we do not have
01:10:30.800 --> 01:10:40.280
that file there and we see hello prithi inside which is crazy so it is okay it happens all
01:10:40.280 --> 01:10:44.800
the time you know so we have to go understand why it is happening that is more important
01:10:44.800 --> 01:10:54.520
than you know this file contains the right file now let us see if we have the correct
01:10:54.520 --> 01:11:10.800
process is running yes then we go and examine it in curl to see if we can get to the local
01:11:10.800 --> 01:11:19.480
host 8760 and we have some response then we get the curl browser and we still get the
01:11:19.480 --> 01:11:30.920
old welcome to nginx page the old page we do not know why so this method did not work
01:11:30.920 --> 01:11:37.520
we do not know why it did not work let us go another method of running the same thing
01:11:37.520 --> 01:11:41.560
maybe it is picking up from some other location maybe this location itself is not where it
01:11:41.560 --> 01:11:47.640
picks from some other location where it picks from so you can go investigate that or let
01:11:47.640 --> 01:11:57.080
us go find out where it is actually picking up so docker ps dash a by grep open to test
01:11:57.080 --> 01:12:05.360
and that image that we have running here will go inside the image docker exec and then identify
01:12:05.360 --> 01:12:11.560
where does nginx actually is storing that image that it expects to pop from like where
01:12:11.560 --> 01:12:16.960
does it showing it from that is the question so we have to go and look at the configuration
01:12:16.960 --> 01:12:23.880
of how nginx is actually looking up that file and that is what i want to hunt down as to
01:12:23.880 --> 01:12:28.640
why is it not picking up the file from that location which we wanted it to because what
01:12:28.640 --> 01:12:34.480
i am doing is i am asking it to look at line number four user share nginx html but it seems
01:12:34.480 --> 01:12:40.280
like it is picking up from some other location not the location we have in line number four
01:12:40.280 --> 01:12:46.200
so where is that location that is what i want to find out which means i need to go do some
01:12:46.200 --> 01:13:11.280
investigation so this requires understanding of how nginx actually runs and apparently
01:13:11.280 --> 01:13:20.560
it is pulling up from var www html as opposed to user share html so line number four was
01:13:20.560 --> 01:13:30.320
wrong sorry line number four was wrong it is seems to be pulling from var www html according
01:13:30.320 --> 01:13:37.280
to the configuration that i am looking at inside the container for nginx right there
01:13:37.280 --> 01:13:48.880
that is where it is picking up from not line four that means line number four was wrong
01:13:48.880 --> 01:13:56.200
my memory was incorrect this is the right location according to what i see in the configuration
01:13:56.200 --> 01:14:04.680
that means this was wrong line number five is correct okay fine found out this is what
01:14:04.680 --> 01:14:09.120
happens in real life when you go by memory and you try something and it does not work
01:14:09.120 --> 01:14:13.560
and then you crashed your head against hard objects to struggle to figure out what is
01:14:13.560 --> 01:14:19.600
going on then you study then you find out that your line number four was wrong then
01:14:19.600 --> 01:14:28.000
you change it and then let us try it again and so we quit the docker container we go
01:14:28.000 --> 01:14:46.460
look at the docker container runtime and we kill that docker container
01:14:46.460 --> 01:14:53.800
we also do a docker image delete so we have to kill the docker image that we created like
01:14:53.800 --> 01:15:05.160
line number 24 then we build the docker image like that line number one and then we run
01:15:05.160 --> 01:15:17.360
it line number 22 and now something is running and let us go quickly check what is running
01:15:17.360 --> 01:15:24.120
and we see hello welcome prithi and then we go to the browser and we see that it shows
01:15:24.120 --> 01:15:36.640
what we expect to see right here so that's how it was so yes struggle happens it needs
01:15:36.640 --> 01:15:42.280
to happen otherwise you will never learn even i don't learn unless i struggle so that's
01:15:42.280 --> 01:15:50.760
the way of life you make mistakes like i did line number four it's okay mistakes are okay
01:15:50.760 --> 01:15:57.120
i mean learn to accept mistakes it happens and it needs to happen otherwise you will
01:15:57.120 --> 01:16:05.160
never learn things change by the way i'm not i'm not mistaken when i said this is what
01:16:05.160 --> 01:16:13.400
i memorize and i remember from my memory and i used it but things changed somewhere and
01:16:13.400 --> 01:16:18.120
they seem to be using this location as opposed to this location so this is the right one
01:16:18.120 --> 01:16:25.880
not that and that is totally fine and things keep changing all the time that's how real
01:16:25.880 --> 01:16:31.720
life is so what you just saw is a real life example it used to be line number four but
01:16:31.720 --> 01:16:38.840
now it is line number five fine you struggle you find out and you fix it so that's how
01:16:38.840 --> 01:16:45.200
you build docker images for your situation containing your files that you create that
01:16:45.200 --> 01:17:03.960
you add and then you run when you build an image so does that help you clarify as to
01:17:03.960 --> 01:17:10.960
what we did and is that you know do you have a question associated with any of these ideas
01:17:10.960 --> 01:17:19.880
that we just handled any any questions on this concept how to build a docker image how
01:17:19.880 --> 01:17:25.480
to push it to a registry i push it to my own registry but you can push it to wherever you
01:17:25.480 --> 01:17:36.600
like like the way i push is in line number seven to my own registry so i can go and push
01:17:36.600 --> 01:17:44.600
it like that and it goes
01:17:44.600 --> 01:17:49.280
and i can see it in a browser window and this is only available to me it's not even outside
01:17:49.280 --> 01:17:58.480
my home that's where you see it it's very rudimentary the user interface is very raw
01:17:58.480 --> 01:18:04.140
i don't care as long as it works i don't have to be fancy looking like this or any any other
01:18:04.140 --> 01:18:08.400
big sites like this i don't have to be fancy looking it needs to work the right way and
01:18:08.400 --> 01:18:18.200
it does so what i do is actually run another docker image to create that thing that is
01:18:18.200 --> 01:18:29.240
called a registry using a image called registry and here it is this image called docker registry
01:18:29.240 --> 01:18:35.960
is just a name of a docker file called registry which creates a docker registry like like
01:18:35.960 --> 01:18:44.240
this that's it it's another docker container that holds images for me it's not complicated
01:18:44.240 --> 01:18:54.600
it's dead simple you just run the registry image on docker hub which means you run it
01:18:54.600 --> 01:19:07.040
like this start your registry pull some image push tag some image push something basic commands
01:19:07.040 --> 01:19:10.240
that's how you begin of course you need to have a computer to run these things and all
01:19:10.240 --> 01:19:17.560
that if you don't have it in your home or your office you use the cloud so that i think
01:19:17.560 --> 01:19:22.760
should cover the topic that we just discussed today what i want to be able to do the next
01:19:22.760 --> 01:19:31.600
time is when we when we run this exact image that we just ran in our own machine locally
01:19:31.600 --> 01:19:35.920
i want to run it in the cloud and that's what we will do next time unless you have a different
01:19:35.920 --> 01:19:42.780
idea you want me to cover and i will tweet about it and we'll run the next step the next
01:19:42.780 --> 01:19:49.840
exercise continuation of what we did today next time same day same time next week and
01:19:49.840 --> 01:19:54.600
i will tweet the details and push the same detail on our website which is this website
01:19:54.600 --> 01:20:02.280
and here you will find the instructions on how to join and you need to put your email
01:20:02.280 --> 01:20:09.640
address here and the tweet will show you the next agenda for the next in the next session
01:20:09.640 --> 01:20:17.120
the next week exactly the same time so that's the idea for for today any questions before
01:20:17.120 --> 01:20:27.520
we disconnect
01:20:27.520 --> 01:20:33.280
and if you don't have any questions that's okay
01:20:33.280 --> 01:20:42.600
so thank you thank you for attending and i will see you guys next time bye bye thanks
01:20:42.600 --> 01:20:47.000
for the session sir i'm disconnecting now