1
00:00:04,500 --> 00:00:07,770
We successfully launched API service using container.

2
00:00:07,770 --> 00:00:13,680
And other than that, we launched one more container and you've seen that it is possible to run API

3
00:00:13,710 --> 00:00:21,330
service in two different containers and access both those API services simultaneously and in such case,

4
00:00:21,330 --> 00:00:26,510
internally in each container Flask web server will be running at the same port 5050.

5
00:00:26,520 --> 00:00:32,759
But you need to expose those internal ports to two different ports on your local computer.

6
00:00:32,759 --> 00:00:38,220
For instance, in one container, this port could be 5050, but in another it must be different.

7
00:00:38,220 --> 00:00:42,120
For instance, 50, 51 or 6000 or something else.

8
00:00:42,120 --> 00:00:43,350
Anything you want.

9
00:00:43,770 --> 00:00:44,430
All right.

10
00:00:44,460 --> 00:00:51,660
Now let's jump inside of the container and have a look at its file system and find inside of the container

11
00:00:51,660 --> 00:00:58,350
working directory that we defined here on this line using workdir instruction and also analyze which

12
00:00:58,350 --> 00:01:05,200
processes are running inside of this container, Please ensure that this container is up and running

13
00:01:05,200 --> 00:01:09,610
and you are able to make some requests to the API server like that.

14
00:01:10,690 --> 00:01:17,650
And now in the new tab, please have a look at the list of containers using Docker PS Command.

15
00:01:17,860 --> 00:01:24,700
Here you'll find the name of the running container and such names are generated automatically by Docker.

16
00:01:25,030 --> 00:01:27,010
In my case, I see such name.

17
00:01:27,010 --> 00:01:32,620
In your case you will see a completely different name, but it is located at the end of this output.

18
00:01:32,710 --> 00:01:38,680
Now, using this name, we will connect to this container using bash process.

19
00:01:38,710 --> 00:01:44,950
One more process will be started and we will be able to get inside of the container using shell.

20
00:01:45,250 --> 00:01:47,440
Let me do that in separate tab.

21
00:01:47,440 --> 00:01:54,640
And if you want to start another process in running container, you need to use command Docker exec.

22
00:01:54,760 --> 00:01:56,980
Next, please add options Dash.

23
00:01:56,980 --> 00:02:05,290
It stands for Interactive and T stands for Terminal and afterwards will be name of the running container.

24
00:02:05,290 --> 00:02:08,919
And in my case, this name is Frosty Beverage.

25
00:02:08,949 --> 00:02:12,230
Let me copy this name from here and paste here.

26
00:02:12,230 --> 00:02:18,640
And after space, please add Bash because we want to run one more process that is called bash.

27
00:02:18,650 --> 00:02:19,610
It is Shell.

28
00:02:20,030 --> 00:02:24,740
Let's now execute such command, and I'm inside of the container.

29
00:02:25,010 --> 00:02:31,220
Here is container ID, and I was placed inside of the working directory slash app.

30
00:02:31,610 --> 00:02:34,040
Let me list files and folders here.

31
00:02:34,790 --> 00:02:42,260
And such files as docker file file file dot log main.py and requirements.txt.

32
00:02:43,220 --> 00:02:51,170
And basically those four files are the same files that are located in the folder in our project here.

33
00:02:51,550 --> 00:02:53,060
Here are those files.

34
00:02:53,800 --> 00:03:00,460
Also accept those four files inside of the app folder should be those hidden files and folders.

35
00:03:00,460 --> 00:03:04,690
Hidden folder and hidden file dot env dot local.

36
00:03:04,720 --> 00:03:06,570
Let's have a look at them as well.

37
00:03:08,110 --> 00:03:13,180
And yes, here is dot vnv folder and dot env dot local file.

38
00:03:13,600 --> 00:03:20,710
But please notice that we discussed before that you should not make dot env dot local file and other

39
00:03:20,710 --> 00:03:23,650
files with environment variables public.

40
00:03:24,130 --> 00:03:29,470
You should keep them only locally on the computer where you run corresponding service.

41
00:03:29,470 --> 00:03:34,710
For instance, front end react application or back end python project doesn't matter.

42
00:03:34,720 --> 00:03:36,730
You should keep them private.

43
00:03:37,000 --> 00:03:45,430
But we see that we actually added such invaded local file to the Docker image and Docker images could

44
00:03:45,430 --> 00:03:51,880
be very easily published, for instance to Docker Hub and anyone might have access to your published

45
00:03:51,880 --> 00:03:53,270
Docker image.

46
00:03:53,720 --> 00:04:00,290
And certainly it's not a good practice to put such sensitive files as files with environment variables

47
00:04:00,290 --> 00:04:02,270
inside of the Docker image.

48
00:04:02,630 --> 00:04:09,320
And if you don't want to do that, you need to use Docker ignore file with list of files that Docker

49
00:04:09,320 --> 00:04:12,650
will ignore and don't add to the Docker image.

50
00:04:13,130 --> 00:04:19,320
But now we are using this Docker image only locally just for development process.

51
00:04:19,339 --> 00:04:24,390
We don't publish such image to Docker hub or other hosting services.

52
00:04:24,410 --> 00:04:31,490
That's why we will keep this file inside of the image and we will not add Docker, ignore and ignore

53
00:04:31,490 --> 00:04:35,120
such file in order to avoid adding it to the image.

54
00:04:35,450 --> 00:04:43,070
This move, when we keep this file inside of the image, allows us to access our API service after we

55
00:04:43,070 --> 00:04:50,000
run it like that with Docker run command and here we only expose port, we publish internal port to

56
00:04:50,000 --> 00:04:55,550
one of the external ports on our computers and we here specify only name of the image.

57
00:04:55,850 --> 00:05:02,360
And this image contains all necessary files, including file with environment variables in order to

58
00:05:02,360 --> 00:05:06,470
be able to run API service as it was run before.

59
00:05:06,500 --> 00:05:12,110
We are still able to access images retrieved from the Unsplash API.

60
00:05:12,140 --> 00:05:17,380
It means that key that is located inside of the local file works as expected.

61
00:05:17,390 --> 00:05:20,690
We use it for request to unsplash API.

62
00:05:20,780 --> 00:05:29,300
Also notice that here inside of this app folder there is sub folder dot env and such folder we created

63
00:05:29,300 --> 00:05:36,110
on purpose before creation of the python virtual environment locally on our computers and such folder

64
00:05:36,110 --> 00:05:42,770
contains such sub folders as being lib and different files and basically inside of the image.

65
00:05:42,770 --> 00:05:50,180
We don't require this dot env folder because as I've told you before, all packages were installed globally

66
00:05:50,180 --> 00:05:51,680
here inside of the container.

67
00:05:51,680 --> 00:05:53,900
And in a moment we will verify that.

68
00:05:54,050 --> 00:06:01,640
That's why it makes sense to add such folder to Docker ignore, but for now we will not do that to keep

69
00:06:01,640 --> 00:06:02,450
it simple.

70
00:06:02,480 --> 00:06:09,350
But please keep in mind that this dot env folder is not required for running our flask web server inside

71
00:06:09,350 --> 00:06:10,370
of the container.

72
00:06:10,400 --> 00:06:11,270
All right.

73
00:06:11,300 --> 00:06:15,680
Key point here is that there is app folder inside of the container.

74
00:06:15,890 --> 00:06:22,910
We could move one level up here and have a look at files and folders here and there are such folders

75
00:06:22,910 --> 00:06:32,180
as home lib media and so on, all folders that are usually present on any Linux like operating system.

76
00:06:32,570 --> 00:06:41,050
And here, along with home dev boot and bin folders, there is app folder with all our project files.

77
00:06:41,060 --> 00:06:47,780
That's why I told you before that you should add such instruction as workdir inside of the Docker file

78
00:06:47,810 --> 00:06:51,860
to put all your application files into separate folder.

79
00:06:52,250 --> 00:06:58,670
Otherwise if you don't add such instruction, all your application files and folders will be placed

80
00:06:58,670 --> 00:07:02,390
here near such folders as home and so on.

81
00:07:02,780 --> 00:07:08,750
And it's not a good practice to do so because at least you could override some folders that are already

82
00:07:08,750 --> 00:07:11,690
present in this root directory here.

83
00:07:12,050 --> 00:07:16,370
All right, now let's analyze Python related installations here.

84
00:07:16,370 --> 00:07:23,420
And first let's have a look at version of the python by entering command Python version and see version

85
00:07:23,420 --> 00:07:25,310
3.9.4.

86
00:07:25,310 --> 00:07:30,470
And that's that exact version, that tech 3.9.2.

87
00:07:30,500 --> 00:07:33,950
We verified it here at Docker Hub.

88
00:07:34,440 --> 00:07:42,420
Tech 3.9 points at the same image as tech three latest and 3.9.4.

89
00:07:43,120 --> 00:07:47,560
That's why we see here exact Python version 3.9.4.

90
00:07:47,590 --> 00:07:48,520
Here it is.

91
00:07:48,730 --> 00:07:53,290
Also could have a look at version of the pap pap version.

92
00:07:53,290 --> 00:07:56,770
And this version is 21 .0.1.

93
00:07:57,100 --> 00:08:04,720
Also told you that Pap installed all dependencies globally inside of the container and that means that

94
00:08:04,720 --> 00:08:09,940
we should be able to access such dependency as flask for instance, globally.

95
00:08:09,940 --> 00:08:11,470
Here inside of the container.

96
00:08:11,500 --> 00:08:18,970
Let's try to check version of the Flask flask dash dash version and get result version of the flask

97
00:08:18,970 --> 00:08:20,380
is 1.1.2.

98
00:08:20,650 --> 00:08:23,200
Same applies to dot env package.

99
00:08:23,200 --> 00:08:27,130
It is also present globally here and it is accessible globally.

100
00:08:27,520 --> 00:08:34,659
If I try to do the same on my computer and enter dot env dash dash version I'll get error command not

101
00:08:34,659 --> 00:08:41,860
found because such package dot env was installed on my computer only inside of the virtual environment.

102
00:08:41,860 --> 00:08:44,179
That's why it is not accessible like that.

103
00:08:44,210 --> 00:08:50,900
But inside of the container we are able to access flask and dot env globally because single purpose

104
00:08:50,900 --> 00:08:54,710
of this container is to run python flask application.

105
00:08:55,130 --> 00:09:00,430
All right, now let's have a look at the processes that are currently running inside of this container.

106
00:09:00,440 --> 00:09:07,700
Please type dash x and you should find list of currently running processes inside of the container and

107
00:09:07,700 --> 00:09:09,440
there are only four of them.

108
00:09:10,460 --> 00:09:17,390
First process with process ID one is called root process, and that is that process that was started

109
00:09:17,390 --> 00:09:19,190
by container initially.

110
00:09:19,400 --> 00:09:24,620
And in our example, command Python plus Main.py was used.

111
00:09:24,620 --> 00:09:27,200
That's why this process is called root process.

112
00:09:27,200 --> 00:09:29,600
And here you see the same command.

113
00:09:29,870 --> 00:09:36,230
This command was entered by us here in the Docker file as last instruction cmd.

114
00:09:36,740 --> 00:09:44,360
Also one more process started here and this process is the same as this one Python Main.py difference

115
00:09:44,360 --> 00:09:50,750
here is that here you see absolute paths and the reason for that is that this process is multithreaded

116
00:09:50,750 --> 00:09:51,530
process.

117
00:09:51,560 --> 00:09:56,780
L here stands for that and this process is root process is session leader.

118
00:09:56,780 --> 00:10:04,910
This small s tells us that also accept Python processes here and here you should see bash process here

119
00:10:04,910 --> 00:10:05,750
on the list.

120
00:10:05,840 --> 00:10:12,450
And we actually started this additional process inside of the container because we opened Bash Shell

121
00:10:12,450 --> 00:10:12,990
here.

122
00:10:13,020 --> 00:10:14,670
That's what you see right now.

123
00:10:14,670 --> 00:10:14,940
It is.

124
00:10:14,940 --> 00:10:15,720
Bash Shell.

125
00:10:16,370 --> 00:10:22,610
Also, we just entered Command X and that's why one more process was created here.

126
00:10:22,850 --> 00:10:26,600
And these are all processes that are running inside of the container.

127
00:10:26,600 --> 00:10:31,460
It is just a single purpose container for running our Python application.

128
00:10:31,460 --> 00:10:34,040
No other processes are present here.

129
00:10:34,070 --> 00:10:35,660
That's the beauty of Docker.

130
00:10:35,660 --> 00:10:40,700
You could create as many containers you want, but each container is single purposed.

131
00:10:40,730 --> 00:10:47,330
Let's now back again to app folder and let's now also have a look at the Requirements.txt file that

132
00:10:47,330 --> 00:10:54,380
is present here in the app directory and recap that this Requirements.txt file was created during image

133
00:10:54,380 --> 00:10:56,810
build process by pipenv.

134
00:10:57,050 --> 00:10:58,520
So let's have a look at it.

135
00:10:58,520 --> 00:11:06,050
Cut requirements dot txt and here are contents of this file and you might find here such dependencies

136
00:11:06,050 --> 00:11:08,780
as flask dash course or flask.

137
00:11:08,780 --> 00:11:16,910
Also there are such dependencies as python dot env and request, but dev packages such as pylint and

138
00:11:16,910 --> 00:11:20,510
black code formatter are absent here in this list.

139
00:11:20,510 --> 00:11:28,310
And I told you before that env does not include dev packages when you generate such txt file out of

140
00:11:28,700 --> 00:11:32,960
file using env LOC requirements command.

141
00:11:32,960 --> 00:11:39,560
But as we verified we were able to successfully run our application because such dependencies as Flask

142
00:11:39,560 --> 00:11:45,020
and flask course are available here and listed in the requirements.txt file.

143
00:11:45,260 --> 00:11:45,830
Great.

144
00:11:45,830 --> 00:11:47,390
Let me show you one more thing.

145
00:11:47,390 --> 00:11:50,690
Let's have a look at main.py file.

146
00:11:50,690 --> 00:11:54,500
And in this file there is such route as new image.

147
00:11:54,500 --> 00:12:02,150
And of course now such main.py file is fully synchronized with Main.py file here in the folder.

148
00:12:02,180 --> 00:12:09,200
But let's try to modify this route for instance, to new image to like that save changes here in this

149
00:12:09,200 --> 00:12:10,490
main.py file.

150
00:12:10,520 --> 00:12:17,670
Go back to container and again have a look at contents of the main.py file and contents here remained

151
00:12:17,700 --> 00:12:18,630
unchanged.

152
00:12:18,720 --> 00:12:20,370
Reason is very simple.

153
00:12:20,370 --> 00:12:27,150
Such main.py file inside of the container is completely different from the main.py file here in the

154
00:12:27,570 --> 00:12:28,290
folder.

155
00:12:28,380 --> 00:12:36,870
And if you want to apply such changes that you made in the folder, you need to rebuild image and rerun

156
00:12:36,870 --> 00:12:37,770
container.

157
00:12:42,780 --> 00:12:46,080
Let's get back to new image root here, as was before.

158
00:12:46,080 --> 00:12:52,230
And now you understand that Main.py file inside of the container is different from the main.py file

159
00:12:52,230 --> 00:12:56,460
inside of the folder in our Visual Studio code project.

160
00:12:57,340 --> 00:12:58,030
All right.

161
00:12:58,030 --> 00:13:01,140
That's how container looks like from inside.

162
00:13:01,150 --> 00:13:03,290
And now let's exit from here.

163
00:13:03,310 --> 00:13:05,290
I hope that idea is fully clear.

164
00:13:05,290 --> 00:13:10,690
And now you understand what happens under the hood when you actually run specific container.

165
00:13:10,690 --> 00:13:12,670
And let me close this tab.

166
00:13:12,910 --> 00:13:13,510
All right.

167
00:13:13,510 --> 00:13:14,920
That's it for this lecture.

168
00:13:14,920 --> 00:13:21,520
And in the next one, let's quickly summarize what we did here, because we are actually done with localization

169
00:13:21,550 --> 00:13:23,290
of the API service.

170
00:13:23,500 --> 00:13:25,420
I'll see you guys after the small pause.

