1
00:00:02,200 --> 00:00:03,850
So we've got this Dockerfile.

2
00:00:03,850 --> 00:00:06,480
How can we now turn this into an image

3
00:00:06,480 --> 00:00:09,285
and then into a container ultimately?

4
00:00:09,285 --> 00:00:11,710
Well, we need to open up the terminal

5
00:00:11,710 --> 00:00:15,010
and again here, I will simply use the terminal integrated

6
00:00:15,010 --> 00:00:18,963
into my IDE, which is the default system terminal though.

7
00:00:19,860 --> 00:00:24,780
And here, we can now run docker

8
00:00:24,780 --> 00:00:27,570
but not run but build

9
00:00:27,570 --> 00:00:29,960
because now I don't wanna run a image,

10
00:00:29,960 --> 00:00:31,390
at least not yet

11
00:00:31,390 --> 00:00:34,600
but first of all, I wanna create an image.

12
00:00:34,600 --> 00:00:36,370
I wanna create an image based

13
00:00:36,370 --> 00:00:38,910
on the instructions in this Dockerfile

14
00:00:38,910 --> 00:00:41,980
and that's what the build command does.

15
00:00:41,980 --> 00:00:46,402
It tells Docker to build a new custom image based

16
00:00:46,402 --> 00:00:47,573
on a Dockerfile.

17
00:00:49,080 --> 00:00:52,700
And here we now need to specify the path

18
00:00:52,700 --> 00:00:55,880
where Docker is able to find the Dockerfile

19
00:00:55,880 --> 00:00:58,120
and if we just type a dot here,

20
00:00:58,120 --> 00:01:00,440
we tell Docker that the Dockerfile

21
00:01:00,440 --> 00:01:02,440
will be in the same folder

22
00:01:02,440 --> 00:01:04,629
as we're running this command in.

23
00:01:04,629 --> 00:01:06,940
And since I'm using the integrated terminal,

24
00:01:06,940 --> 00:01:10,150
this is already navigated into this project folder.

25
00:01:10,150 --> 00:01:13,160
Hence the Dockerfile is in that folder.

26
00:01:13,160 --> 00:01:15,290
Hence, if I hit Enter,

27
00:01:15,290 --> 00:01:18,100
this now creates this image.

28
00:01:18,100 --> 00:01:20,650
And you see it executes a couple of steps here.

29
00:01:20,650 --> 00:01:24,963
It executes the FROM command to take the node image.

30
00:01:25,980 --> 00:01:28,060
Sets the working directory.

31
00:01:28,060 --> 00:01:29,550
Copies our code.

32
00:01:29,550 --> 00:01:31,100
Runs npm install.

33
00:01:31,100 --> 00:01:33,374
We can ignore the warnings here.

34
00:01:33,374 --> 00:01:35,980
Then exposes the port.

35
00:01:35,980 --> 00:01:38,703
And recognizes this command you could say.

36
00:01:39,890 --> 00:01:41,320
And at the end, it's done

37
00:01:41,320 --> 00:01:44,600
and it built an image with this name here,

38
00:01:44,600 --> 00:01:46,040
with this ID.

39
00:01:46,040 --> 00:01:49,290
Now, keep in mind, as mentioned in the first course module,

40
00:01:49,290 --> 00:01:51,560
on Windows, the output looks a bit differently.

41
00:01:51,560 --> 00:01:54,223
Here you find your image ID here.

42
00:01:55,880 --> 00:01:58,390
You can also assign custom names to images

43
00:01:58,390 --> 00:02:00,740
but for the moment, we can go with that.

44
00:02:00,740 --> 00:02:03,550
So copy the ID that was generated

45
00:02:03,550 --> 00:02:08,550
and then you can run docker run and use that ID here.

46
00:02:08,800 --> 00:02:10,550
And if you hit Enter,

47
00:02:10,550 --> 00:02:12,810
this will now start this container

48
00:02:12,810 --> 00:02:15,130
and you will see it doesn't finish,

49
00:02:15,130 --> 00:02:17,080
it keeps on running.

50
00:02:17,080 --> 00:02:20,470
The reason for that is that the command we executed here

51
00:02:20,470 --> 00:02:22,570
starts a Node server,

52
00:02:22,570 --> 00:02:26,840
which is also an ongoing process that doesn't finish.

53
00:02:26,840 --> 00:02:29,520
And therefore, the container also keeps on running

54
00:02:29,520 --> 00:02:32,130
because the command that was executed

55
00:02:32,130 --> 00:02:33,800
when the container is started

56
00:02:33,800 --> 00:02:36,410
is a command that doesn't finish.

57
00:02:36,410 --> 00:02:39,220
And hence, the container keeps on going.

58
00:02:39,220 --> 00:02:40,270
But you will notice

59
00:02:40,270 --> 00:02:43,810
that if you visit localhost,

60
00:02:43,810 --> 00:02:46,340
you won't see the website,

61
00:02:46,340 --> 00:02:49,770
even though we exposed the port here

62
00:02:49,770 --> 00:02:50,723
in our Dockerfile.

63
00:02:52,420 --> 00:02:53,850
So why is that not working

64
00:02:53,850 --> 00:02:55,640
and what can we do here?

65
00:02:55,640 --> 00:02:57,680
Well, are almost here.

66
00:02:57,680 --> 00:03:00,350
First of all, let's shut this container down

67
00:03:00,350 --> 00:03:03,140
because clearly, it's not working as intended.

68
00:03:03,140 --> 00:03:06,220
To do that, you can open up a new terminal

69
00:03:06,220 --> 00:03:08,280
and there run docker ps

70
00:03:08,280 --> 00:03:10,750
to see all the processes.

71
00:03:10,750 --> 00:03:13,090
And if you just run docker ps,

72
00:03:13,090 --> 00:03:17,820
without -a, you see only the running processes.

73
00:03:17,820 --> 00:03:21,020
And here we see one container based

74
00:03:21,020 --> 00:03:23,240
on this image we created.

75
00:03:23,240 --> 00:03:25,540
And it's still up and running here

76
00:03:25,540 --> 00:03:28,925
because as I said, it doesn't quit automatically.

77
00:03:28,925 --> 00:03:32,050
Now, we can stop this container manually

78
00:03:32,050 --> 00:03:34,560
by running docker stop

79
00:03:34,560 --> 00:03:36,170
and then using the container name,

80
00:03:36,170 --> 00:03:38,273
which was automatically assigned here.

81
00:03:39,500 --> 00:03:40,850
If I now hit Enter,

82
00:03:40,850 --> 00:03:42,660
this takes a short while

83
00:03:42,660 --> 00:03:45,100
and it will shut down this container

84
00:03:45,100 --> 00:03:48,050
and therefore also the Node server running inside

85
00:03:48,050 --> 00:03:48,993
of the container.

86
00:03:50,260 --> 00:03:52,000
Once this is finished,

87
00:03:52,000 --> 00:03:54,260
if you run docket ps again,

88
00:03:54,260 --> 00:03:56,510
you see no running container anymore.

89
00:03:56,510 --> 00:04:00,020
Instead now you would have to enter ps -a

90
00:04:00,020 --> 00:04:02,010
to see your container there.

91
00:04:02,010 --> 00:04:03,313
It now exited.

92
00:04:04,490 --> 00:04:07,740
Okay, so now we shut this down.

93
00:04:07,740 --> 00:04:08,940
What went wrong though?

94
00:04:08,940 --> 00:04:11,660
Why were we not able to listen

95
00:04:11,660 --> 00:04:15,530
on port 80 for this custom container?

96
00:04:15,530 --> 00:04:18,350
Because one step is missing here.

97
00:04:18,350 --> 00:04:23,220
Yes, we have this EXPOSE 80 instruction in our Dockerfile

98
00:04:23,220 --> 00:04:26,840
but actually, this instruction only is added

99
00:04:26,840 --> 00:04:29,500
for documentation purposes.

100
00:04:29,500 --> 00:04:31,840
It doesn't really do anything.

101
00:04:31,840 --> 00:04:34,280
It is a best practice to add it

102
00:04:34,280 --> 00:04:37,860
and you should add it to clearly document

103
00:04:37,860 --> 00:04:41,340
which ports will be exposed by your container

104
00:04:41,340 --> 00:04:42,680
but you need to do more.

105
00:04:42,680 --> 00:04:47,120
You could actually also remove this EXPOSE 80 instruction

106
00:04:47,120 --> 00:04:49,640
and still do what I'm about to show you

107
00:04:49,640 --> 00:04:51,100
and it would still work.

108
00:04:51,100 --> 00:04:54,590
So this instruction is really 100% optional,

109
00:04:54,590 --> 00:04:58,550
yet as mentioned, recommended that you add it.

110
00:04:58,550 --> 00:05:02,330
But what really maters is that when you run the container

111
00:05:02,330 --> 00:05:07,108
with docker run that you then add a special option.

112
00:05:07,108 --> 00:05:09,480
So therefore, what we need to do

113
00:05:09,480 --> 00:05:11,350
is we need to run this container

114
00:05:11,350 --> 00:05:15,900
but we need to add a extra flag here

115
00:05:15,900 --> 00:05:20,319
and that's the -p flag in front of the image name,

116
00:05:20,319 --> 00:05:23,060
which stands for publish.

117
00:05:23,060 --> 00:05:25,330
And this allows us to tell Docker

118
00:05:25,330 --> 00:05:28,160
under which local port,

119
00:05:28,160 --> 00:05:31,640
so under which port on our machine here

120
00:05:31,640 --> 00:05:35,830
this internal Docker container-specific port

121
00:05:35,830 --> 00:05:37,870
should be accessible.

122
00:05:37,870 --> 00:05:41,530
And the syntax here is as follows.

123
00:05:41,530 --> 00:05:43,120
You have -p

124
00:05:43,120 --> 00:05:46,870
and then you specify your local port

125
00:05:46,870 --> 00:05:49,620
under which you wanna access this application.

126
00:05:49,620 --> 00:05:53,470
In this case, for example, 3000.

127
00:05:53,470 --> 00:05:55,110
This is up to you.

128
00:05:55,110 --> 00:05:56,890
And then colon

129
00:05:56,890 --> 00:06:01,110
and then the internal Docker container exposed port.

130
00:06:01,110 --> 00:06:02,840
In this case, 80,

131
00:06:02,840 --> 00:06:05,713
since we're exposing 80 in this container.

132
00:06:07,460 --> 00:06:09,900
And with this now if we hit Enter,

133
00:06:09,900 --> 00:06:11,668
this again starts

134
00:06:11,668 --> 00:06:16,668
but now if I reload localhost:3000,

135
00:06:16,990 --> 00:06:21,990
I see my application and I can Learn Docker in-depth

136
00:06:22,130 --> 00:06:25,030
because now this is published

137
00:06:25,030 --> 00:06:26,870
under the local port 3000.

138
00:06:27,945 --> 00:06:32,190
And this is now our first custom image based

139
00:06:32,190 --> 00:06:34,560
on the default Node image

140
00:06:34,560 --> 00:06:36,630
with our own instructions

141
00:06:36,630 --> 00:06:39,460
and our own Node app.

142
00:06:39,460 --> 00:06:41,690
And I'm pretty sure that it at this point,

143
00:06:41,690 --> 00:06:44,950
there still are many question marks in your mind

144
00:06:44,950 --> 00:06:45,900
and in your eyes

145
00:06:45,900 --> 00:06:47,810
and I will get to all of them

146
00:06:47,810 --> 00:06:52,020
but I hope this general idea here is clear.

147
00:06:52,020 --> 00:06:54,770
That we have a custom image based

148
00:06:54,770 --> 00:06:56,600
on a existing image,

149
00:06:56,600 --> 00:07:01,010
the node image, where we then have a couple of instructions.

150
00:07:01,010 --> 00:07:03,030
For example, to copy our code

151
00:07:03,030 --> 00:07:05,500
and install all dependencies.

152
00:07:05,500 --> 00:07:07,960
And then, we create this image

153
00:07:07,960 --> 00:07:10,340
with the docker build command

154
00:07:10,340 --> 00:07:14,420
and we then run a container based on that created image

155
00:07:14,420 --> 00:07:16,203
with the docker run command.

156
00:07:17,200 --> 00:07:18,170
And then here again,

157
00:07:18,170 --> 00:07:20,200
this container is still up and running.

158
00:07:20,200 --> 00:07:21,514
If we wanna close it,

159
00:07:21,514 --> 00:07:23,640
if we wanna stop it,

160
00:07:23,640 --> 00:07:26,450
we again have to first of all, find the container name

161
00:07:26,450 --> 00:07:29,340
with docker ps here.

162
00:07:29,340 --> 00:07:33,690
And then we can run docker stop container name.

163
00:07:33,690 --> 00:07:35,770
And of course, there are also ways

164
00:07:35,770 --> 00:07:37,100
of assigning your own names

165
00:07:37,100 --> 00:07:40,380
and so on and we'll get to these ways

166
00:07:40,380 --> 00:07:42,700
and these features as well

167
00:07:42,700 --> 00:07:45,630
but for now, these are the basics you should be aware of.

168
00:07:45,630 --> 00:07:47,640
How to build your own image,

169
00:07:47,640 --> 00:07:49,770
how to run that image as a container,

170
00:07:49,770 --> 00:07:51,350
how to stop that container

171
00:07:51,350 --> 00:07:52,421
and most importantly,

172
00:07:52,421 --> 00:07:55,813
you should understand how these core concepts work together.

