WEBVTT

00:00.230 --> 00:03.470
In this section we're going to build three images.

00:03.470 --> 00:10.460
One image is going to package up a Ruby environment that will be used to execute Ruby source code.

00:10.460 --> 00:17.000
One image is going to package up a Python environment that will be used to execute Python code, and

00:17.000 --> 00:23.810
another image will be used to package up a go environment that will be used to execute go source code.

00:23.810 --> 00:30.980
So if we go to my schematic and Docker, we use docker files to build Docker images.

00:32.030 --> 00:39.830
This docker file is going to build an image that pulls the Ruby base image from Docker Hub, and the

00:39.830 --> 00:47.150
base image is the foundation onto which additional layers of the overarching image will be added.

00:47.300 --> 00:56.690
The second layer will copy the script dot rb file the Ruby source code into a working directory.

00:56.690 --> 01:02.330
So at this point, the Docker image is going to have the source code at some working directory.

01:02.330 --> 01:07.500
It's going to have the ruby environment that will be needed to execute the source code.

01:07.530 --> 01:14.220
The last step is for it to provide the container that we will create from this image, with the commands

01:14.220 --> 01:16.800
that it can use to execute the app.

01:16.800 --> 01:22.590
So over here in step number three, a container is created from the Docker image.

01:22.590 --> 01:28.650
The container has access to the source code inside of the image, as well as the ruby environment inside

01:28.650 --> 01:29.700
of the image as well.

01:29.700 --> 01:36.720
All it has to do is run the command that was provided to it, and it's going to be able to execute the

01:36.720 --> 01:39.690
Ruby source code and start up a process.

01:39.720 --> 01:41.160
All right.

01:41.850 --> 01:45.600
So step one is going to be to create this Docker file.

01:45.600 --> 01:48.360
Let's do it right now.

01:48.360 --> 01:51.660
So we'll go to the Ruby Docker file.

01:51.660 --> 01:54.900
And we're going to have to CD into this directory.

01:54.900 --> 02:01.980
So right now I'm at Docker course remastered main I'm going to have to CD into Workbook starter projects

02:02.010 --> 02:09.220
go into oh two starter projects, followed by Ruby user input.

02:09.250 --> 02:11.500
Let me get a drink of water real quick.

02:17.650 --> 02:18.700
All right.

02:19.960 --> 02:25.420
Now the base image is going to be Ruby 3.0.

02:25.450 --> 02:31.810
The base image is going to be the foundation onto which additional layers of our overarching image will

02:31.810 --> 02:32.440
be added.

02:32.470 --> 02:39.070
The working directory where we're going to place our Ruby source code will be slash app.

02:39.250 --> 02:42.280
Really, you can choose any working directory you want.

02:42.310 --> 02:43.690
I'm going to choose app.

02:43.690 --> 02:46.390
That's kind of my go to default.

02:46.660 --> 02:53.920
The code that I'm going to copy into the working directory will be script dot RB.

02:56.920 --> 03:00.190
And the destination is the working directory.

03:00.190 --> 03:05.440
Everything we do after step two happens inside of the working directory.

03:05.440 --> 03:09.020
So by putting a dot on the second argument.

03:09.050 --> 03:14.570
I'm saying copy script RB into the working directory.

03:15.620 --> 03:16.520
Okay.

03:16.610 --> 03:23.240
And then finally the image that we build needs to provide the container that's created from it with

03:23.240 --> 03:27.260
a command that the container can use to execute the application.

03:27.260 --> 03:29.930
Ruby script dot RB.

03:31.580 --> 03:32.630
All right.

03:34.100 --> 03:40.220
Now what I can do is say Docker build dash t.

03:40.280 --> 03:44.030
I'm going to call the image Ruby app.

03:44.990 --> 03:50.900
And we're going to create an image from the Docker file inside of the current directory.

03:50.900 --> 03:56.180
So dot when used in this context means current directory.

03:56.210 --> 03:57.200
All right.

03:57.200 --> 04:00.590
For some reason the folder is called Ruby user input.

04:00.680 --> 04:01.820
That doesn't make much sense.

04:01.820 --> 04:03.950
But anyways it's just the name

04:08.540 --> 04:11.550
Should have been called something like Ruby app or something.

04:11.550 --> 04:12.360
Whatever.

04:13.500 --> 04:17.070
So now it's pulling the image from Docker Hub.

04:18.480 --> 04:21.300
That step is taking quite a long time.

04:21.300 --> 04:23.550
That took a solid 10s.

04:23.550 --> 04:29.370
After doing so, it created the working directory and copied our scriptdb file into it.

04:29.460 --> 04:33.330
And now I can say docker run.

04:34.200 --> 04:37.140
I'm going to create a container that gets removed as soon as we're done with it.

04:38.190 --> 04:42.390
Um, the container is going to be called Ruby App container.

04:43.050 --> 04:47.010
And we're going to create a container from the image that we just built.

04:47.040 --> 04:49.380
Ruby app.

04:49.920 --> 04:50.880
That's it.

04:51.780 --> 04:53.010
Beautiful.

04:53.250 --> 04:59.070
It is able to execute the application before I move on.

04:59.070 --> 05:02.790
What I want to do is start up an interactive shell inside of the container.

05:02.790 --> 05:10.170
So to do that I can say dash it Right over here.

05:12.160 --> 05:17.140
Followed by slash bin slash shell.

05:18.430 --> 05:19.060
All right.

05:19.060 --> 05:25.510
If I say LZ, you can see that the container has already navigated into the working directory, which

05:25.510 --> 05:33.430
means by executing the the command ruby script RB, it was able to execute the app.

05:33.430 --> 05:41.080
So I'm basically simulating what the container did for us previously I can say LZ and I can CD out of

05:41.080 --> 05:42.100
this directory.

05:42.130 --> 05:43.420
Press LZ again.

05:43.420 --> 05:52.240
And here I can see the working directory slash app, I can CD into uh, the working directory and see

05:52.240 --> 05:55.180
the application that was stored inside of it.

05:55.180 --> 05:58.120
That is why our container is able to access it.

05:58.120 --> 05:59.770
All right, enough about that.

05:59.770 --> 06:04.750
I'm going to exit and CD out of Ruby user input.

06:04.750 --> 06:06.640
Again, this name doesn't make much sense.

06:06.640 --> 06:08.440
It should have been called something else.

06:08.470 --> 06:12.460
I'm going to CD into Python script.

06:12.490 --> 06:17.060
This is the next image that we're going to build.

06:17.540 --> 06:18.860
All right.

06:20.000 --> 06:24.470
Um, once again we start by setting the base image.

06:24.500 --> 06:33.530
Python 3.8 slim, the working directory where we are going to copy over the application.

06:33.530 --> 06:36.110
We're just going to let it be slash app.

06:36.110 --> 06:42.260
We're going to copy script dot p y into the working directory.

06:42.260 --> 06:46.520
Remember everything after step two happens inside of the working directory.

06:46.520 --> 06:53.210
Then we're going to give the container a command that it can use to run the application at the Workdir.

06:53.210 --> 06:57.470
So Python script dot p y.

06:57.620 --> 07:05.600
And remember that this application is programmed to accept, uh, any number of command line arguments.

07:05.600 --> 07:10.190
We're going to pass in one command line argument of I am silly.

07:11.090 --> 07:15.900
So it's going to happen Here is let's go over here.

07:16.740 --> 07:22.320
From the Docker file, we're building a Docker image that contains a pre-configured Python environment

07:22.320 --> 07:27.450
that's going to be pulled from Docker Hub, as well as an application that's going to be mounted at

07:27.450 --> 07:28.860
the working directory.

07:29.070 --> 07:34.290
Then we're providing whatever container is going to be created from this image with a command that it

07:34.290 --> 07:38.880
can use to execute the application at the working directory.

07:39.120 --> 07:44.460
It will start up a process inside of the container from the source code, and pass into the running

07:44.490 --> 07:46.770
app command line arguments.

07:46.800 --> 07:48.240
All right.

07:48.240 --> 07:53.100
So let's go ahead and say oh I need I am CD into Python script.

07:53.100 --> 07:54.780
But let me clean up this mess.

07:54.810 --> 07:55.800
Clear.

07:56.280 --> 07:59.490
Now I'm going to say docker build T.

07:59.640 --> 08:03.240
We'll call the image python script.

08:04.590 --> 08:09.000
Create an image from the docker file at the current directory.

08:09.000 --> 08:11.400
It's pulling Python 3.8 slim.

08:11.430 --> 08:13.260
All right we're good.

08:13.530 --> 08:17.070
Now I'm going to say docker run dash dash m.

08:17.070 --> 08:17.080
Em.

08:17.950 --> 08:25.180
Um, we'll call the container Python script container.

08:25.510 --> 08:30.370
We'll create a container from the image Python script.

08:31.090 --> 08:33.340
Everything works beautifully.

08:33.370 --> 08:40.150
Now I can start up an interactive shell in the interest of looking into the container itself.

08:40.690 --> 08:42.490
Here, I'll just say dash it.

08:46.120 --> 08:47.710
Oh, forgot the dot.

08:48.250 --> 08:49.750
I mean, the dash.

08:53.230 --> 08:53.920
All right.

08:53.980 --> 09:00.910
LZ so as you can see, once again the container automatically navigates to the working directory and

09:00.940 --> 09:03.580
is ready to run the application inside of it.

09:03.610 --> 09:11.740
So now from the working directory our container ran the command python script.py with the command line

09:11.740 --> 09:12.250
argument.

09:12.250 --> 09:13.390
I am silly

09:17.320 --> 09:20.030
Oh, I keep making mistakes.

09:20.900 --> 09:23.630
Python script.py.

09:24.140 --> 09:25.370
I am silly.

09:32.060 --> 09:38.480
And we see a different output because the container ran it as one argument, whereas we ran it as three

09:38.480 --> 09:39.290
separate arguments.

09:39.290 --> 09:41.510
I am followed by silly.

09:41.540 --> 09:43.490
All right, let's exit.

09:44.060 --> 09:48.920
Move on to the last image we're going to create from the following.

09:48.920 --> 09:54.530
So we'll CD out of Python script CD into go environment variables.

09:55.970 --> 10:00.200
All right clear the terminal output.

10:00.950 --> 10:03.890
Once again we start from the base image.

10:03.890 --> 10:10.310
In this case the environment that we're going to use that we're going to package up alongside the source

10:10.310 --> 10:15.260
code is going to be Golang version 1.16.

10:16.550 --> 10:20.570
Then we're going to set up a working directory slash app.

10:20.660 --> 10:28.380
Then we can copy the main dot go file into the working directory.

10:28.470 --> 10:33.090
Once we do that, we can provide the container with a command that it can use the application that it

10:33.090 --> 10:37.200
can use to execute the application at that working directory.

10:37.230 --> 10:39.360
Why am I using the command workdir.

10:39.660 --> 10:45.810
So that command is going to be um main dot.

10:46.050 --> 10:47.370
Uh, go.

10:48.270 --> 10:49.530
Run.

10:50.670 --> 10:51.900
Main dot.

10:51.930 --> 10:52.800
Go.

10:53.550 --> 10:54.600
All right.

10:56.850 --> 11:05.970
Uh, the last thing we got to do is build this up into an image docker build, dash t go app.

11:07.410 --> 11:12.090
Looking at the schematic, we're building an image from the Docker file.

11:12.090 --> 11:18.690
The image is going to have a go environment as well as the go source code copied into the working directory.

11:18.690 --> 11:23.980
The Docker image is going to provide the container that's created from it with a command that it can

11:23.980 --> 11:26.800
use to run the application.

11:26.830 --> 11:31.900
When the container runs the application, it's going to start up a go process within the container,

11:31.900 --> 11:37.990
and then we can pass the necessary environment variables into the application that's running inside

11:37.990 --> 11:38.890
the container.

11:38.890 --> 11:46.090
And you'll remember that the environment variables that the application expects to receive from its

11:46.090 --> 11:48.610
environment is called message.

11:49.510 --> 11:58.540
So over here we can say docker run dash dash m dash name.

11:59.500 --> 12:01.360
We're going to call it go app.

12:03.070 --> 12:08.650
And we can create an image a container from the following image.

12:09.850 --> 12:11.290
Now we'll call it go app container.

12:11.290 --> 12:16.090
And then we're going to create a container from the go app image.

12:16.390 --> 12:25.420
And we're going to pass into the application that's running inside the container an environment variable

12:25.620 --> 12:32.010
called message that equals hello from Docker.

12:32.670 --> 12:33.780
Let's try it out.

12:36.270 --> 12:39.240
Um, did I mess up?

12:40.860 --> 12:43.680
Oh, I'm such a knucklehead.

12:43.710 --> 12:52.860
I placed the environment variable between the name and between the name flag and the actual name.

12:52.860 --> 12:59.310
So here we'll say dash e message is equal to hello from Docker.

13:00.210 --> 13:04.020
These mistakes can happen when you've been looking at a screen for too long.

13:04.020 --> 13:05.580
I recommend you go outside.

13:05.580 --> 13:10.350
Go for a hike, don't do what I'm doing and we are good.

13:10.620 --> 13:11.790
All right.

13:11.790 --> 13:14.460
So now I'm going to say docker run.

13:17.430 --> 13:22.080
Um, let's start up an interactive shell dash it

13:25.500 --> 13:26.730
Slash bin.

13:26.760 --> 13:28.110
Slash shell.

13:28.800 --> 13:34.080
So here we've launched an interactive shell inside of the container that's currently running.

13:34.080 --> 13:37.290
The container has an environment variable set up message.

13:37.290 --> 13:38.760
Hello from Docker.

13:38.760 --> 13:46.020
If I say ls, uh, we see that the container has already gone into the working directory and is ready

13:46.020 --> 13:47.700
to execute Main.go.

13:47.700 --> 13:56.160
So now if we say go run Main.go, the container is going to run the go application and pass into it

13:56.160 --> 13:58.170
the environment variable message.

13:58.200 --> 14:00.600
Hello from Docker.

14:01.170 --> 14:02.280
Beautiful.

14:02.640 --> 14:04.050
Now we exit.

14:04.920 --> 14:06.030
We're good to go.

14:06.240 --> 14:08.370
That is it for the section.

14:08.370 --> 14:15.810
In the next section we're going to be looking at Containerizing web applications and microservices.

14:15.840 --> 14:16.770
All right.

14:16.770 --> 14:24.090
All of this is just one big e-commerce application split up into different microservices.

14:24.090 --> 14:27.300
This is very close to stuff that you can expect in the real world.

14:27.300 --> 14:29.280
And I can't wait to see you there.
