WEBVTT

00:00.170 --> 00:00.530
All right.

00:00.560 --> 00:03.140
Now we're going to move on to starter code number eight.

00:03.170 --> 00:09.110
Before we do, I want to make note of the fact that our container commands are getting really, really

00:09.110 --> 00:09.680
messy.

00:09.710 --> 00:12.230
We have two different terminals.

00:12.230 --> 00:15.710
Each one of them is running a different process.

00:15.710 --> 00:20.600
And we had to orchestrate each container to run inside of the same network.

00:20.600 --> 00:27.770
And if you think about it, what if we had an application with six different microservices interacting

00:27.770 --> 00:28.340
with each other?

00:28.370 --> 00:34.370
Are we going to start up six different terminals, run them all in the same network, and uh, give

00:34.370 --> 00:38.120
each one environment variables within the command itself?

00:38.120 --> 00:43.220
What if one of the containers had like six different environment environment variables that it needed

00:43.220 --> 00:44.810
to function properly?

00:44.900 --> 00:49.550
You can already see how things are going to get really messy when we do that.

00:49.550 --> 00:58.670
So what we're going to do is set up a Docker compose file that has all of the container definitions

00:58.670 --> 01:00.600
written inside of it.

01:00.600 --> 01:03.840
That way when we call docker compose up.

01:03.870 --> 01:07.650
Docker compose is going to start up all the containers for us.

01:07.650 --> 01:08.790
And when we call.

01:08.820 --> 01:14.700
Docker compose down, docker compose is going to destroy the containers for us and do the cleanup.

01:14.700 --> 01:21.120
And the great thing about Docker compose is that all the containers are going to be running inside of

01:21.120 --> 01:24.990
the same environment, which means they're going to be part of the same network.

01:24.990 --> 01:35.130
So Docker Compose also orchestrates that for us, which means from here I can simply refer to the node

01:35.130 --> 01:41.610
server container name as the host, uh, followed by the port, and therefore be able to connect to

01:41.640 --> 01:43.830
the application that's running inside of it.

01:44.670 --> 01:45.840
All right.

01:46.350 --> 01:47.940
Uh, pretty cool stuff.

01:47.940 --> 01:48.960
Very promising stuff.

01:48.960 --> 01:53.850
Before we do anything, I'm going to remove this terminal.

01:53.880 --> 02:02.530
Remove this terminal, and I'm going to say Docker system Prune dash a I want to delete everything.

02:02.860 --> 02:05.440
Make sure there are no more images.

02:05.440 --> 02:08.350
We still have the great submission API for whatever reason.

02:08.350 --> 02:10.120
Let's just remove it forcefully.

02:10.150 --> 02:13.150
Docker image m.

02:16.780 --> 02:23.380
Say dash f to force it couldn't be forced it because image is being used by a running container.

02:23.380 --> 02:32.890
So we'll say docker PS dash a remove this container first docker rm container id dash f.

02:34.270 --> 02:36.010
Then we'll remove the image.

02:36.010 --> 02:43.600
All right let's start from a clean slate docker images docker PS dash a.

02:44.140 --> 02:45.310
All right let's get started.

02:45.310 --> 02:46.240
Enough talking.

02:46.240 --> 02:53.200
So what I want to do is start by setting a version of three for docker compose.

02:53.230 --> 03:00.030
And the docker compose environment is going to start up a bunch of services.

03:00.210 --> 03:07.320
Every service in Docker compose is going to be a container that's running some sort of application,

03:07.320 --> 03:08.820
some sort of service.

03:09.030 --> 03:13.470
Indenting in a YAML file is really important.

03:13.470 --> 03:22.020
So if I want to specify a service within this field of services I'm going to press enter and then press

03:22.020 --> 03:22.920
tab.

03:22.920 --> 03:27.960
So everything I do here belongs to services.

03:28.080 --> 03:31.680
One of the services is going to be a flask app.

03:32.700 --> 03:33.240
Okay.

03:33.240 --> 03:40.110
So right here I'm specifying that I want to run a container called flask app.

03:41.040 --> 03:44.310
The image from which we're going to create this container.

03:44.310 --> 03:46.620
Again the indentation is really important.

03:46.620 --> 03:48.060
Press enter.

03:48.060 --> 03:55.690
And now the image from which we're going to create this container is going to be the one that we pushed

03:55.690 --> 03:57.520
onto Docker Hub.

03:57.730 --> 04:01.570
I'm going to pull this image 1.0.0.

04:01.600 --> 04:07.660
I'm not going to do latest because what if in the future I pushed an image that was incompatible with

04:07.660 --> 04:10.120
this great submission API?

04:10.150 --> 04:13.570
I want to be specific about the version itself.

04:13.750 --> 04:14.800
All right.

04:15.820 --> 04:22.150
And now the container that we create from this container definition, it's automatically going to be

04:22.150 --> 04:23.770
called flask app.

04:23.770 --> 04:26.770
But I want to specify a container name regardless.

04:26.770 --> 04:30.250
And notice how I've got this autocomplete set up.

04:30.580 --> 04:34.570
That's mainly because I've got the Docker extension installed on VSCode.

04:34.570 --> 04:36.130
Make sure that you do the same.

04:36.130 --> 04:40.810
I'm pretty sure there was a section about that in the very beginning of this course.

04:40.900 --> 04:41.470
All right.

04:41.470 --> 04:44.770
So now I'm going to specify ports.

04:45.670 --> 04:51.280
Now ports unlike these fields accepts an array of fields.

04:51.280 --> 04:54.890
An array in YAML is represented like this.

04:55.910 --> 05:00.320
Um, you press enter, followed by a tab.

05:01.610 --> 05:07.190
Tab, meaning any port we specify here belongs to this field.

05:07.370 --> 05:09.290
One of the ports.

05:11.390 --> 05:15.830
Here we can map the container port to a host machine port.

05:16.250 --> 05:20.840
This is equivalent to the port mapping that we were using in our command.

05:20.840 --> 05:28.310
But the nice thing is, instead of writing command flags, we can specify everything in one file.

05:28.310 --> 05:33.320
We're basically just converting the commands from before into container definitions.

05:33.590 --> 05:34.610
All right.

05:34.610 --> 05:45.410
And you'll remember that the flask application relied on an environment variable that is equal to node

05:45.410 --> 05:51.860
server, which is going to be the name of the container where we run our great submission API.

05:52.100 --> 05:59.250
Okay, That is all the environment variables that the Great Submission Portal relies on.

05:59.310 --> 06:03.600
The next thing we need to do is say depends on.

06:03.600 --> 06:08.130
So what service does this flask app rely on?

06:08.130 --> 06:12.030
It relies on a great submission API service.

06:12.060 --> 06:16.650
We're going to call the container that is hosting that service node server.

06:17.070 --> 06:22.920
So this dictates the order in which Docker compose creates the container.

06:22.920 --> 06:25.200
In this case we're telling Docker compose.

06:25.200 --> 06:30.060
Create the node server container first because the flask app depends on it.

06:30.060 --> 06:32.400
Then create the flask app container.

06:32.640 --> 06:34.590
You'll see that all in action.

06:34.740 --> 06:35.520
All right.

06:35.550 --> 06:43.830
Now we're going to make sure that we're at the same level as the flask app service so that we can create

06:44.190 --> 06:47.970
the node server container service.

06:48.060 --> 06:48.720
All right.

06:48.750 --> 07:00.100
Press tab the image that we're going to use to create this node server container is going to be the

07:00.100 --> 07:02.860
one that we pushed onto Docker Hub.

07:03.430 --> 07:04.540
All right.

07:06.310 --> 07:14.980
And we're going to use image version 1.0.0 because it is the one that's compatible with this portal.

07:16.510 --> 07:17.770
All right.

07:18.430 --> 07:23.440
The container name is going to be Node server.

07:23.470 --> 07:26.890
It's really important that you call the container node server.

07:26.890 --> 07:34.030
Because our flask app container is providing the application inside of it with an environment variable.

07:34.030 --> 07:37.030
Great service host equal to node server.

07:37.030 --> 07:39.430
And now we specify the ports.

07:39.430 --> 07:47.440
The great submission API, if we look at the documentation runs on port 3000 of the container, we can

07:47.440 --> 07:52.730
just map that to port 3000 of our host machine.

07:53.180 --> 07:57.950
So we got the port mapping set up and that's pretty much it.

07:58.580 --> 07:59.870
Pretty easy, don't you think?

07:59.870 --> 08:02.900
If I go ahead, let me go.

08:02.900 --> 08:05.420
Uh, just one second, guys.

08:09.740 --> 08:11.540
Where is that pesky command?

08:12.890 --> 08:20.480
If I go ahead and copy this over here, we basically just recreated this command, but inside of Docker

08:20.480 --> 08:21.080
compose.

08:21.080 --> 08:23.480
So here we've got the port mapping.

08:24.110 --> 08:28.040
Here we've got the image from which we're creating the container.

08:28.910 --> 08:31.730
Here it's just a random output.

08:31.820 --> 08:35.960
We don't need to specify a network anymore okay.

08:36.620 --> 08:44.150
So now what I'm going to do is once again Docker system prune dash a make sure everything is really

08:44.150 --> 08:44.870
gone.

08:48.440 --> 08:49.000
All right.

08:49.000 --> 08:50.470
It did delete the network.

08:50.470 --> 08:51.280
My network.

08:51.280 --> 08:52.180
Anyways.

08:52.210 --> 08:55.690
Now I need to CD out of grade submission API.

08:56.440 --> 08:59.980
I'm at oh seven starter code.

08:59.980 --> 09:10.840
I need to be inside of oh eight starter code, CD, CD out of that CD into oh eight starter code.

09:10.870 --> 09:14.560
Anyways docker compose up.

09:15.070 --> 09:17.830
So notice how it starts by creating the node server.

09:17.830 --> 09:20.530
And then it's going to create the flask application.

09:20.530 --> 09:21.820
So great service.

09:21.820 --> 09:24.640
So the node server starts running on port 3000.

09:24.670 --> 09:26.200
The flask app depends on it.

09:26.200 --> 09:35.650
So it runs second which means now if I go to localhost 5001

09:36.760 --> 09:39.280
everything should work smoothly.

09:39.310 --> 09:45.130
Harry, give him a score of 94 in potions.

09:45.610 --> 09:47.540
Everything works beautifully.

09:47.570 --> 09:49.880
The flask.

09:49.880 --> 09:55.880
The application running inside the flask app container was able to seamlessly interact with the application

09:55.880 --> 09:58.760
running inside the node server container.

09:58.910 --> 10:05.870
Because they're both running inside the same Docker compose environment, we pass an environment variable

10:05.870 --> 10:16.160
of grade service host or whatever equal to node server into the application running inside of the flask

10:16.190 --> 10:17.060
app container.

10:17.090 --> 10:23.690
It was able to make an HTTP request with the host name, node, server and port of 3000.

10:23.720 --> 10:30.200
The node server host name allows it to find the container node server running inside of the same network,

10:30.200 --> 10:36.800
giving it access to the application that's running on port 3000 of the container, and therefore be

10:36.830 --> 10:39.350
able to make requests to it.

10:39.650 --> 10:42.320
And then that was pretty much it.

10:43.640 --> 10:51.900
Now we're going to move on Or before we do anything, we need to remove all of these containers.

10:52.320 --> 10:58.380
And the way we're going to do it is we're not going to stop this process ourselves on a separate terminal.

10:58.410 --> 11:02.250
We're going to say docker compose down.

11:03.960 --> 11:08.910
I'm at the wrong directory, so I need to go inside of oh eight starter code.

11:14.520 --> 11:16.770
Docker compose down.

11:17.220 --> 11:18.900
It removed the containers.

11:18.900 --> 11:21.000
It's stopping the node server currently.

11:21.240 --> 11:25.110
It's taking quite a bit of time to do it, but it is what it is.

11:25.140 --> 11:27.900
As long as it's doing the cleanup for us, I don't care.

11:27.930 --> 11:30.450
It removed both containers.

11:30.450 --> 11:33.150
It removed the network that they were both running on.

11:33.150 --> 11:35.880
So Docker Compose created the network for us.

11:35.880 --> 11:37.080
Isn't that pretty cool?

11:37.110 --> 11:41.460
Ran them both inside the same network and that's all she wrote.

11:41.640 --> 11:45.360
Now let's move on to starter code number nine.
