WEBVTT

00:00.350 --> 00:01.160
Welcome back.

00:01.160 --> 00:06.230
Now go ahead and open up the workbook starter projects.

00:06.530 --> 00:12.950
Uh, now we're going to run a Ruby app, a Python app, as well as a go app without installing any of

00:12.950 --> 00:16.670
their respective, uh, environments into our machine.

00:16.670 --> 00:20.900
Everything is going to happen inside of Docker itself.

00:20.900 --> 00:23.000
Let's start with the Ruby application.

00:23.000 --> 00:29.150
So many of you are probably not familiar with Ruby, uh, and probably never will use Ruby after this

00:29.150 --> 00:30.050
course.

00:30.050 --> 00:31.280
And that's okay.

00:31.280 --> 00:37.970
We're just going to run a simple Ruby application for the sake of demonstrating that regardless of whatever

00:38.030 --> 00:41.750
app you're running, the process is going to be similar.

00:41.900 --> 00:48.290
Okay, now, am I going to force you to install the Ruby environment into your machine just to run this

00:48.290 --> 00:48.620
app?

00:48.620 --> 00:55.220
No, everything is going to happen inside of Docker itself, which is the beauty of running Docker containers.

00:55.220 --> 01:00.560
So here, the developer who created this app, they're telling us how to run it bare metal.

01:00.560 --> 01:05.660
We are going to modify the command so that it runs within our container properly.

01:05.660 --> 01:07.790
So let's go ahead and create a docker container.

01:07.790 --> 01:10.010
Docker run dash v.

01:11.140 --> 01:17.170
Actually, before we do any mounting, we're going to specify the flag dash dash RM to remove the container

01:17.170 --> 01:18.430
once we're done with it.

01:18.550 --> 01:21.730
And dash v we're going to use to mount.

01:21.730 --> 01:23.770
Let's go to the ruby schematic.

01:26.220 --> 01:34.740
We're going to use it to mount the source code that is inside of our host machine into a working directory

01:34.740 --> 01:36.630
within our Docker container.

01:37.080 --> 01:37.920
All right.

01:37.920 --> 01:41.160
So we need to get the path.

01:43.460 --> 01:52.670
Where our code lives in our machine and mount it into some working directory inside of our container.

01:52.670 --> 01:57.980
You can call the working directory whatever you want, as long as you're consistent when you provide

01:57.980 --> 02:00.200
the container with a command.

02:01.960 --> 02:06.670
We're going to call the container, uh, Ruby application.

02:08.460 --> 02:10.170
And the container.

02:10.170 --> 02:14.130
Now it has the application mounted at the working directory.

02:14.160 --> 02:19.080
Now it needs a Ruby environment in order to run this app.

02:19.080 --> 02:22.230
Going over to Docker Hub, let's write Ruby.

02:23.500 --> 02:28.090
And this is the official repo for a bunch of Ruby images.

02:28.330 --> 02:34.060
Uh, we're going to get the Ruby image tagged 3.0.0.

02:34.060 --> 02:34.960
Okay.

02:39.620 --> 02:46.730
And let's go ahead and pull Ruby 3.0.0 into our Docker container.

02:46.730 --> 02:50.510
So at this point our container has the Ruby image.

02:50.510 --> 02:56.660
Remember an image is a snapshot of a preconfigured environment taken at a specific point in time that

02:56.660 --> 03:00.770
we can use to run this Ruby app.

03:00.770 --> 03:03.830
So now we can provide the container with the command Ruby.

03:05.300 --> 03:08.750
Slash app slash scriptdb.

03:08.780 --> 03:15.890
So it's using the Ruby command to run the script dot rb file that it's going to be inside of the container's

03:15.890 --> 03:17.240
working directory.

03:17.270 --> 03:18.770
Let's go ahead and run this.

03:18.800 --> 03:21.650
It's unable to find the ruby image locally.

03:21.650 --> 03:29.690
So it's going to pull this pre-configured ruby environment into our local Docker cache, where our container

03:29.690 --> 03:35.540
can have direct access to it and thereby execute this Ruby command on our app.

03:35.540 --> 03:37.760
And that's exactly what it did.

03:37.790 --> 03:38.240
All right.

03:38.270 --> 03:41.900
Now let's move on to the Python script.

03:42.230 --> 03:43.280
All right.

03:43.280 --> 03:46.100
So let's go ahead and press clear.

03:46.100 --> 03:54.620
And I'm going to go to my Docker dashboard which you can access on Mac by going over here and clicking

03:54.620 --> 04:00.710
on the go to dashboard icon on windows by going over to the bottom right toolbar, clicking the bottom,

04:00.710 --> 04:02.090
clicking the Docker icon.

04:02.090 --> 04:03.410
It'll take you here.

04:03.440 --> 04:07.910
Remember what's nice about Docker is everything happens inside of it.

04:07.910 --> 04:11.690
So by virtue of removing this Ruby image.

04:12.730 --> 04:15.340
It's like nothing ever happened.

04:15.960 --> 04:18.630
There is no trace of any ruby.

04:19.720 --> 04:25.450
Activity on our system, and there are no containers because we specify dash dash m.

04:25.660 --> 04:27.160
Now we move on.

04:27.990 --> 04:29.310
To the Python app.

04:29.310 --> 04:34.800
So again we're going to mount the Python app into the working directory of whatever container we create.

04:34.800 --> 04:39.360
We're going to pull a Python environment so that our container can use it.

04:40.300 --> 04:40.990
Um.

04:41.940 --> 04:47.970
Then we're going to run the Python application by giving it command line arguments as well.

04:47.970 --> 04:53.970
So the script.py file was programmed to accept command line arguments.

04:53.970 --> 05:01.230
So when we provide the container with the uh with the executing command, we need to make sure to give

05:01.230 --> 05:04.530
it the arguments that the application expects.

05:04.530 --> 05:05.910
All right.

05:05.910 --> 05:11.760
So let's say Docker run and we're going to create a container that automatically gets removed.

05:11.760 --> 05:14.850
Once we're done with it then we're going to say volume mount.

05:14.850 --> 05:18.000
We're going to mount we're going to get the path.

05:19.010 --> 05:24.410
The folder where the application lives, and we're going to mount whatever is inside of the Python script

05:24.410 --> 05:28.580
folder into a working directory within our container.

05:28.610 --> 05:32.750
We're going to call the container Python script container.

05:33.110 --> 05:39.200
And we're going to create we're going to pull the image Python 3.8 slim.

05:39.200 --> 05:44.360
So we're so for the sake of exercise we're going to locate it within Docker Hub.

05:44.600 --> 05:46.580
Go to the official Python repo.

05:46.580 --> 05:47.960
With all of the images.

05:47.960 --> 05:52.610
We're going to look for the image tagged 3.8 slim.

05:53.770 --> 05:55.450
This one right here.

05:55.450 --> 06:01.090
We're going to pull that so that our container can use it to execute the command.

06:01.090 --> 06:03.400
Python script.py.

06:03.670 --> 06:08.560
And the application that exists at our container's working directory.

06:08.560 --> 06:12.550
It expects command line arguments within the command itself.

06:12.550 --> 06:17.500
So um, we can just say hello from Docker.

06:17.500 --> 06:22.750
We're going to give it three command line arguments unable to find the image locally.

06:22.750 --> 06:25.030
So we pull it from Docker Hub.

06:25.810 --> 06:28.570
Can't open file script.py.

06:28.600 --> 06:31.870
No such file or directory I messed up.

06:31.870 --> 06:39.220
The application is inside of our container's working directory slash app, so I need to specify.

06:40.390 --> 06:47.890
Python slash app slash Script.py so that it can find the application within the working directory that

06:47.890 --> 06:49.180
we mounted it to.

06:49.180 --> 06:56.350
And then we give that application the command line arguments that it that it that it is expecting.

06:56.470 --> 06:57.310
All right.

06:57.310 --> 06:59.320
Hello from Docker.

06:59.710 --> 07:02.650
And so now we move on to the go application.

07:03.820 --> 07:08.980
Uh, this app expects an environment variable named message to customize the greeting.

07:09.010 --> 07:17.380
Now, an environment variable is a key value pair that an application expects to receive from the environment

07:17.380 --> 07:18.460
that it's running in.

07:18.460 --> 07:26.140
So in this case, the container is going to be responsible for providing this application with the message

07:26.140 --> 07:30.670
environment variable so that this app can function accordingly.

07:30.700 --> 07:31.390
All right.

07:31.390 --> 07:38.560
So let's write clear to clear the output and create a container docker run dash dash rm that's going

07:38.560 --> 07:41.500
to mount the application at this path.

07:43.060 --> 07:47.800
Into the working directory of this Docker container.

07:49.410 --> 07:51.840
And we're going to call the container.

07:51.870 --> 07:52.830
Go.

07:54.050 --> 07:55.070
Container.

07:57.030 --> 07:59.640
And we're going to pull.

08:02.850 --> 08:09.900
The image Golang 1.16 into our container.

08:17.170 --> 08:18.880
1.16.

08:19.450 --> 08:22.180
Let's just verify the image.

08:22.420 --> 08:23.770
Make sure it exists.

08:23.770 --> 08:24.760
It does.

08:26.270 --> 08:33.560
So we're going to use this pre-configured Golang environment in order to run our application using the

08:33.560 --> 08:35.870
command go run.

08:35.900 --> 08:42.590
Now the Main.go file is going to be located within the container's working directory slash app.

08:42.590 --> 08:47.510
So we say go run slash app slash Main.go.

08:47.510 --> 08:54.290
And there's one thing I forgot to do, which is to provide this application that is going to be run

08:54.290 --> 08:57.470
within the container with environment variables.

08:57.470 --> 09:04.520
So when the container wants to provide its underlying application environment variables, it does so

09:04.520 --> 09:07.280
using the flag dash e.

09:07.880 --> 09:08.840
All right.

09:08.840 --> 09:14.990
And the environment variable that the app is expecting is called message.

09:14.990 --> 09:25.370
So we say dash e message is equal to some value which we can say hello from Docker.

09:26.680 --> 09:27.610
All right.

09:27.610 --> 09:29.620
And now if you press enter.

09:29.800 --> 09:34.960
Unable to find the Golang image locally so it pulls it from Docker Hub.

09:36.700 --> 09:43.090
And once it pulls the image, it can use it to execute the following command and run our go app.

09:43.120 --> 09:44.560
Beautiful.

09:44.590 --> 09:51.910
Our container was able to successfully run the go application and provide it with the environment variable

09:51.910 --> 09:54.310
that the app was expecting.

09:54.340 --> 10:02.770
Now I just want to note the difference between an environment variable that you see here, and the command

10:02.770 --> 10:06.190
line argument that we passed into the Python script.

10:06.310 --> 10:11.650
A command line argument is any value that you can pass directly to the application when running it from

10:11.650 --> 10:19.330
the command line, and an environment variable is a specific key value pair that an application is expecting

10:19.360 --> 10:22.420
to receive from the environment that it's running in.

10:22.420 --> 10:29.020
So command line argument any value environment variable it's expecting a particular key value pair.

10:29.050 --> 10:29.950
All right.

10:29.950 --> 10:36.010
So we were able to run a go application a Python application and a Ruby application without installing

10:36.010 --> 10:37.510
anything in our system.

10:37.510 --> 10:43.090
This would not change whether we're using Java, whether we're using C plus plus.

10:43.090 --> 10:48.880
You just need to make sure that you pull the appropriate image into the container.

10:48.880 --> 10:55.930
Once you have that image, you can run whatever commands you need to run in order to execute said app.

10:55.930 --> 10:59.680
Before we wrap up, go to your Docker dashboard.

10:59.680 --> 11:02.590
Delete all the images that we pulled.

11:03.380 --> 11:05.240
Uh, delete whatever.

11:05.240 --> 11:07.370
Containers haven't been deleted already.

11:07.370 --> 11:09.260
And you should be golden.

11:09.260 --> 11:13.610
I will see you in the next section when we discuss Docker files.

11:13.610 --> 11:14.750
See you then.
