1
00:00:02,150 --> 00:00:05,200
Now in the vast majority of use cases,

2
00:00:05,200 --> 00:00:09,300
you don't just want to download and run an image

3
00:00:09,300 --> 00:00:11,380
that gives you an interactive shell

4
00:00:11,380 --> 00:00:14,140
like the node image does at the moment.

5
00:00:14,140 --> 00:00:16,180
This is nice to get started

6
00:00:16,180 --> 00:00:20,940
and to have our first experience with containers and images,

7
00:00:20,940 --> 00:00:23,620
but it's not all we wanna do.

8
00:00:23,620 --> 00:00:28,540
Instead, typically you build up on those space images

9
00:00:28,540 --> 00:00:30,700
to then build your own images.

10
00:00:30,700 --> 00:00:32,310
Like for example here,

11
00:00:32,310 --> 00:00:34,920
we could build up on the node image

12
00:00:34,920 --> 00:00:39,920
to then execute certain node JS code with that image.

13
00:00:39,980 --> 00:00:43,650
And of course, node is just one example here.

14
00:00:43,650 --> 00:00:46,470
An example I will use a lot throughout the course,

15
00:00:46,470 --> 00:00:49,430
but the same would be true for PHP,

16
00:00:49,430 --> 00:00:51,570
for GO, for Python,

17
00:00:51,570 --> 00:00:54,580
whichever programming language you're using,

18
00:00:54,580 --> 00:00:57,370
whichever application you might be building.

19
00:00:57,370 --> 00:01:01,830
Typically you would pull into your official base image

20
00:01:01,830 --> 00:01:05,150
and then add your code on top of that

21
00:01:05,150 --> 00:01:08,200
to execute your code with that image.

22
00:01:08,200 --> 00:01:10,370
And of course you wanna do all of that

23
00:01:10,370 --> 00:01:11,823
inside of a container.

24
00:01:12,770 --> 00:01:16,400
And that is a scenario where you need to build

25
00:01:16,400 --> 00:01:20,530
your own image because your exact application

26
00:01:20,530 --> 00:01:22,170
with your code.

27
00:01:22,170 --> 00:01:25,730
Of course, this does not exist on Docker hub

28
00:01:25,730 --> 00:01:27,960
unless you shared it dear.

29
00:01:27,960 --> 00:01:31,290
So therefore, now we'll build our own image

30
00:01:31,290 --> 00:01:34,350
building up on this node image though,

31
00:01:34,350 --> 00:01:38,980
and for that I prepared a very simple node JS dummy project

32
00:01:38,980 --> 00:01:43,610
and you don't need to know node to follow along.

33
00:01:43,610 --> 00:01:46,470
You can simply download this dummy project.

34
00:01:46,470 --> 00:01:51,470
You find it attached and it contains four files here,

35
00:01:51,710 --> 00:01:53,280
a server JS file,

36
00:01:53,280 --> 00:01:57,210
which contains our main node application code.

37
00:01:57,210 --> 00:01:58,890
In case you know node,

38
00:01:58,890 --> 00:02:00,940
you can quickly see what this does

39
00:02:00,940 --> 00:02:02,900
In case you don't know it,

40
00:02:02,900 --> 00:02:07,120
this starts a web server with node JS,

41
00:02:07,120 --> 00:02:09,270
listening on port 80

42
00:02:09,270 --> 00:02:14,270
and we handle incoming requests to two URLs

43
00:02:14,560 --> 00:02:17,380
to our domain slash nothing

44
00:02:17,380 --> 00:02:20,160
if it's a get HTTP request,

45
00:02:20,160 --> 00:02:23,563
in which case this HTML code will be returned.

46
00:02:24,530 --> 00:02:29,020
And we handle post requests to store a goal

47
00:02:29,020 --> 00:02:33,390
where we then try to retrieve a goal key,

48
00:02:33,390 --> 00:02:37,170
a goal value from the incoming request body.

49
00:02:37,170 --> 00:02:40,000
We then lock this goal to the console

50
00:02:40,000 --> 00:02:43,830
and we set some user goal variable equal

51
00:02:43,830 --> 00:02:45,490
to that extracted goal.

52
00:02:45,490 --> 00:02:49,150
And then we redirect to the slash route again

53
00:02:49,150 --> 00:02:51,000
so to this route

54
00:02:51,000 --> 00:02:53,690
and here we then render HTML code

55
00:02:53,690 --> 00:02:57,590
where we utilize this user goal variable,

56
00:02:57,590 --> 00:02:59,680
which has a default value,

57
00:02:59,680 --> 00:03:03,370
which is eventually overwritten to the entered goal value.

58
00:03:03,370 --> 00:03:06,120
And this variable is output here.

59
00:03:06,120 --> 00:03:09,760
This is Java script code executed with node

60
00:03:09,760 --> 00:03:13,140
to bring up such a node web server.

61
00:03:13,140 --> 00:03:15,490
But again, you don't need to know node.

62
00:03:15,490 --> 00:03:17,310
This course is not about node.

63
00:03:17,310 --> 00:03:19,870
This is just one example application

64
00:03:19,870 --> 00:03:21,960
which you wanna dockerize,

65
00:03:21,960 --> 00:03:24,683
which we wanna run in a Docker container.

66
00:03:26,340 --> 00:03:30,380
Now, two other key things belong to this application.

67
00:03:30,380 --> 00:03:33,590
One key thing is the public folder,

68
00:03:33,590 --> 00:03:36,890
which has a CSS file for some styling.

69
00:03:36,890 --> 00:03:39,960
This file is automatically loaded in the end

70
00:03:39,960 --> 00:03:41,710
by telling the node server

71
00:03:41,710 --> 00:03:45,910
to well, just redirect requests to files

72
00:03:45,910 --> 00:03:47,390
to the public folder

73
00:03:47,390 --> 00:03:49,750
and then look for such files there,

74
00:03:49,750 --> 00:03:51,850
which is why I request two styles.

75
00:03:51,850 --> 00:03:56,463
CSS will load style CSS, which is in the public folder,

76
00:03:57,330 --> 00:03:59,710
but then probably the more important

77
00:03:59,710 --> 00:04:02,500
our key thing we have here

78
00:04:02,500 --> 00:04:05,990
is the package.json file.

79
00:04:05,990 --> 00:04:09,500
Here, we describe this node application

80
00:04:09,500 --> 00:04:12,250
and that is a node exclusive concept.

81
00:04:12,250 --> 00:04:14,420
It has nothing to do with Docker,

82
00:04:14,420 --> 00:04:16,300
this package.json file.

83
00:04:16,300 --> 00:04:17,579
But here we tell node

84
00:04:17,579 --> 00:04:19,610
which dependencies we have,

85
00:04:19,610 --> 00:04:21,899
which other third party packages

86
00:04:21,899 --> 00:04:25,340
we need to run this node application

87
00:04:25,340 --> 00:04:28,150
in this case that's the express framework

88
00:04:28,150 --> 00:04:29,870
which is a node JS package

89
00:04:29,870 --> 00:04:32,397
we can use in our node JS applications

90
00:04:32,397 --> 00:04:35,083
and the body parser package.

91
00:04:36,140 --> 00:04:39,330
Now, if you would want to run this project locally

92
00:04:39,330 --> 00:04:43,480
without Docker, you would need to install Node JS

93
00:04:43,480 --> 00:04:45,660
from nodejs.org.

94
00:04:45,660 --> 00:04:48,530
For example, that latest version

95
00:04:48,530 --> 00:04:52,020
and then thereafter in your project folder

96
00:04:52,020 --> 00:04:55,163
in a terminal opened in that folder.

97
00:04:56,530 --> 00:04:58,860
And here, this is my default terminal

98
00:04:58,860 --> 00:05:01,870
just integrated in visual studio code,

99
00:05:01,870 --> 00:05:03,670
the idea I'm using here,

100
00:05:03,670 --> 00:05:06,790
automatically navigated into this project folder.

101
00:05:06,790 --> 00:05:10,790
And in this terminal, you would need to run NPM install.

102
00:05:10,790 --> 00:05:13,500
NPM is another tool shipping together

103
00:05:13,500 --> 00:05:14,790
with node JS,

104
00:05:14,790 --> 00:05:16,660
so being installed automatically

105
00:05:16,660 --> 00:05:17,960
when you install Node

106
00:05:17,960 --> 00:05:20,280
and NPM install will now download

107
00:05:20,280 --> 00:05:22,523
and install all the dependencies we need.

108
00:05:23,590 --> 00:05:26,226
And then thereafter, once you did this,

109
00:05:26,226 --> 00:05:30,600
you could execute the server JS file with the node command.

110
00:05:30,600 --> 00:05:33,440
And this would then start the server

111
00:05:33,440 --> 00:05:36,290
and on local host, port 80,

112
00:05:36,290 --> 00:05:40,270
you could visit this application, set your goal

113
00:05:44,010 --> 00:05:45,323
and see this in action.

114
00:05:46,300 --> 00:05:49,110
Now this is the node application running locally

115
00:05:49,110 --> 00:05:52,360
without Docker and you don't need to install Node.

116
00:05:52,360 --> 00:05:56,740
This was just an example how we would run it without Docker.

117
00:05:56,740 --> 00:05:59,120
Now, of course, this course is about Docker though.

118
00:05:59,120 --> 00:06:02,210
So let's quit this with Ctrl + C.

119
00:06:02,210 --> 00:06:04,260
Let's clear this console

120
00:06:04,260 --> 00:06:06,510
and let's actually delete the node

121
00:06:06,510 --> 00:06:08,010
modules folder

122
00:06:08,010 --> 00:06:10,833
which was created after running NPM install.

123
00:06:11,690 --> 00:06:12,800
And let's all deletes,

124
00:06:12,800 --> 00:06:15,620
the package dash lock json file here.

125
00:06:15,620 --> 00:06:17,883
So that we're back to the initial files.

126
00:06:18,870 --> 00:06:21,290
The get ignore file, by the way is optional.

127
00:06:21,290 --> 00:06:22,950
It's just important if you're using

128
00:06:22,950 --> 00:06:25,040
get for version control.

129
00:06:25,040 --> 00:06:27,120
So this is now a node application.

130
00:06:27,120 --> 00:06:29,760
How can we now build our own image

131
00:06:29,760 --> 00:06:32,170
that contains this application

132
00:06:32,170 --> 00:06:37,170
and that then also utilizes the node Docker hub image

133
00:06:37,240 --> 00:06:38,853
to run that code?

