1
00:00:02,120 --> 00:00:03,770
Now with the bind mount added,

2
00:00:03,770 --> 00:00:05,630
if we changed the HTML files,

3
00:00:05,630 --> 00:00:08,180
those changes are instantly reflected,

4
00:00:08,180 --> 00:00:10,380
when we reload the app here.

5
00:00:10,380 --> 00:00:12,220
You'll notice a problem though,

6
00:00:12,220 --> 00:00:14,980
if you change something in server JS.

7
00:00:14,980 --> 00:00:16,530
So Indy JavaScript code,

8
00:00:16,530 --> 00:00:18,780
which is executed by a note.

9
00:00:18,780 --> 00:00:21,590
Let's say there, for example,

10
00:00:21,590 --> 00:00:25,880
I simply want to console log, test here.

11
00:00:25,880 --> 00:00:28,530
Just to change anything.

12
00:00:28,530 --> 00:00:30,430
So I wanna Log test here,

13
00:00:30,430 --> 00:00:32,533
whenever we save a new feedback.

14
00:00:33,490 --> 00:00:36,370
Now my container is still up and running.

15
00:00:36,370 --> 00:00:40,050
You can always check this with Docker PS, of course.

16
00:00:40,050 --> 00:00:45,050
And therefore if I reload, and I try this,

17
00:00:45,220 --> 00:00:47,900
of course it works, but to now see whether,

18
00:00:47,900 --> 00:00:49,920
we also see that log.

19
00:00:49,920 --> 00:00:53,280
We can, of course now use Docker logs

20
00:00:55,640 --> 00:00:57,170
feedback-app.

21
00:00:57,170 --> 00:00:59,540
And we see nothing here.

22
00:00:59,540 --> 00:01:01,610
There is absolutely nothing.

23
00:01:01,610 --> 00:01:04,420
So somehow this wasn't logged.

24
00:01:04,420 --> 00:01:07,040
And that's a node specific problem,

25
00:01:07,040 --> 00:01:09,270
but you might face similar issues

26
00:01:09,270 --> 00:01:11,870
in other applications as well.

27
00:01:11,870 --> 00:01:15,950
This code in server JS is executed by node,

28
00:01:15,950 --> 00:01:17,543
by the node runtime.

29
00:01:18,430 --> 00:01:22,180
And it that runtime, and that file being executed.

30
00:01:22,180 --> 00:01:25,080
Which is responsible for us seeing this page

31
00:01:25,080 --> 00:01:27,860
and having a working web server.

32
00:01:27,860 --> 00:01:30,730
Now we need to restart the web server,

33
00:01:30,730 --> 00:01:33,690
to pick up changes in the JavaScript code

34
00:01:33,690 --> 00:01:35,730
that is used by that server.

35
00:01:35,730 --> 00:01:38,330
We don't need to restart the entire container,

36
00:01:38,330 --> 00:01:40,660
but just the web server.

37
00:01:40,660 --> 00:01:42,730
Now, if the container is already running,

38
00:01:42,730 --> 00:01:45,790
restarting just the server in that container,

39
00:01:45,790 --> 00:01:48,020
is not really trivial though.

40
00:01:48,020 --> 00:01:50,882
So actually, the best thing we can do here,

41
00:01:50,882 --> 00:01:53,574
is to simply stop that container

42
00:01:53,574 --> 00:01:57,140
and then restart it thereafter.

43
00:01:57,140 --> 00:02:00,130
At least we don't need to rebuild the image.

44
00:02:00,130 --> 00:02:02,270
But by stopping and restarting,

45
00:02:02,270 --> 00:02:05,179
we start a new node server,

46
00:02:05,179 --> 00:02:08,430
which will pick up this server JS file.

47
00:02:08,430 --> 00:02:11,380
But of course, since I added --rm

48
00:02:11,380 --> 00:02:13,570
when I created the container,

49
00:02:13,570 --> 00:02:15,470
actually we can't start it again,

50
00:02:15,470 --> 00:02:18,100
because it was deleted once I stopped it.

51
00:02:18,100 --> 00:02:21,623
So here I would have to run Docker, run again.

52
00:02:22,580 --> 00:02:25,203
But with that done, if I now reload,

53
00:02:26,700 --> 00:02:28,820
this should work.

54
00:02:28,820 --> 00:02:30,680
And I save here,

55
00:02:30,680 --> 00:02:33,440
we should now be able to see the logs.

56
00:02:33,440 --> 00:02:36,320
If we use Docker logs feedback-app.

57
00:02:36,320 --> 00:02:37,750
Here it is.

58
00:02:37,750 --> 00:02:41,520
So it's better than having to rebuild the entire image,

59
00:02:41,520 --> 00:02:42,520
but still not great.

60
00:02:43,970 --> 00:02:46,440
Now for note JS, that's a common problem though.

61
00:02:46,440 --> 00:02:48,010
And you might also be facing it

62
00:02:48,010 --> 00:02:52,350
if you're just developing locally without Docker at all.

63
00:02:52,350 --> 00:02:55,310
And there is a useful extra package,

64
00:02:55,310 --> 00:02:58,550
which we can use in node JS development,

65
00:02:58,550 --> 00:03:01,090
which will watch the file system,

66
00:03:01,090 --> 00:03:03,490
and which will restart the node server,

67
00:03:03,490 --> 00:03:05,300
whenever a file changed.

68
00:03:05,300 --> 00:03:07,600
It's a package which be used during development,

69
00:03:07,600 --> 00:03:11,963
therefore, to ensure that changes are reflected instantly.

70
00:03:12,920 --> 00:03:15,350
And for that here in packaged.json,

71
00:03:15,350 --> 00:03:18,370
you should add a devDependencies node,

72
00:03:18,370 --> 00:03:20,003
next to dependencies.

73
00:03:20,890 --> 00:03:22,660
And in their, add nodemon.

74
00:03:26,270 --> 00:03:30,313
And then the version 2.0.4, for example.

75
00:03:31,190 --> 00:03:35,003
That's now an extra dependency added to this project.

76
00:03:36,010 --> 00:03:38,270
And now we can run server JS,

77
00:03:38,270 --> 00:03:40,440
with this nodemon package,

78
00:03:40,440 --> 00:03:42,880
instead off with node itself.

79
00:03:42,880 --> 00:03:45,550
Under the hood nodemon of course uses node,

80
00:03:45,550 --> 00:03:49,020
but it has this extra file change watcher,

81
00:03:49,020 --> 00:03:52,410
which ensures that, we are made aware of

82
00:03:52,410 --> 00:03:53,823
changes in our files.

83
00:03:54,670 --> 00:03:57,280
For that We should add a script section,

84
00:03:57,280 --> 00:04:01,010
a scripts section to package.json as well.

85
00:04:01,010 --> 00:04:03,760
And in there add a script named start,

86
00:04:03,760 --> 00:04:07,660
and type nodemon server.js in here.

87
00:04:07,660 --> 00:04:10,310
And now we can run this script here

88
00:04:10,310 --> 00:04:14,760
to use nodemon, to start our server,

89
00:04:14,760 --> 00:04:15,883
Instead of node.

90
00:04:16,760 --> 00:04:20,200
With that done we now also need to tweak our Docker file,

91
00:04:20,200 --> 00:04:21,910
to utilize this new script

92
00:04:21,910 --> 00:04:25,890
and use this script to start our process,

93
00:04:25,890 --> 00:04:26,723
our server.

94
00:04:26,723 --> 00:04:28,140
Instead of using node.

95
00:04:28,140 --> 00:04:30,070
And they offer in the Docker file,

96
00:04:30,070 --> 00:04:34,173
the command you wanna execute is now actually npm start.

97
00:04:35,670 --> 00:04:37,610
Which uses this start script,

98
00:04:37,610 --> 00:04:40,690
which then under the hood uses nodemon.

99
00:04:40,690 --> 00:04:42,560
So if we now saved this,

100
00:04:42,560 --> 00:04:45,480
we need to remove our

101
00:04:45,480 --> 00:04:50,070
feedback-node:volumes image.

102
00:04:50,070 --> 00:04:52,440
And for that, of course, I first of all,

103
00:04:52,440 --> 00:04:55,710
needs to stop my feedback app container.

104
00:04:55,710 --> 00:04:58,620
Otherwise the image is still in use.

105
00:04:58,620 --> 00:05:00,730
So let's do that first.

106
00:05:00,730 --> 00:05:03,197
Then remove the image

107
00:05:03,197 --> 00:05:06,640
and then build the image again to pick up this new

108
00:05:06,640 --> 00:05:08,320
command here at the end.

109
00:05:08,320 --> 00:05:09,610
And once that is all done,

110
00:05:09,610 --> 00:05:12,130
we can of course use our Docker run command again,

111
00:05:12,130 --> 00:05:14,500
to bring this server back up,

112
00:05:14,500 --> 00:05:16,690
now using this latest image.

113
00:05:16,690 --> 00:05:18,970
And now the key difference is that

114
00:05:18,970 --> 00:05:22,680
this server should now automatically restart,

115
00:05:22,680 --> 00:05:25,830
whenever we change anything in server JS.

116
00:05:25,830 --> 00:05:27,770
So if I add a couple of exclamation marks here,

117
00:05:27,770 --> 00:05:30,160
for example, in this log statement,

118
00:05:30,160 --> 00:05:31,673
and I saved this.

119
00:05:32,580 --> 00:05:36,530
If I now test 4,

120
00:05:36,530 --> 00:05:37,743
test this.

121
00:05:38,820 --> 00:05:40,910
This all works,

122
00:05:40,910 --> 00:05:45,010
but now if I run Docker logs feedback-app,

123
00:05:45,010 --> 00:05:47,300
we see these exclamation marks here.

124
00:05:47,300 --> 00:05:50,140
And we actually also see some output from nodemon,

125
00:05:50,140 --> 00:05:52,010
which proves that it works.

126
00:05:52,010 --> 00:05:54,250
You'll see that it started and you'll see that it,

127
00:05:54,250 --> 00:05:57,660
for example, restarted due to changes here.

128
00:05:57,660 --> 00:06:00,810
Now I got an important note for windows users,

129
00:06:00,810 --> 00:06:04,620
especially when you're using WSL2

130
00:06:04,620 --> 00:06:07,480
for running Docker on windows.

131
00:06:07,480 --> 00:06:08,480
If you're doing that,

132
00:06:08,480 --> 00:06:10,060
you might notice that,

133
00:06:10,060 --> 00:06:12,600
when for me, file changes

134
00:06:12,600 --> 00:06:15,250
do reload D development server,

135
00:06:15,250 --> 00:06:18,730
and everything does work as shown in the lecture,

136
00:06:18,730 --> 00:06:20,950
it doesn't work for you.

137
00:06:20,950 --> 00:06:24,680
The reason for that is that, when using WSL2,

138
00:06:24,680 --> 00:06:28,612
you should store your project and your project files,

139
00:06:28,612 --> 00:06:32,590
directly in the Linux file system

140
00:06:32,590 --> 00:06:33,423
in the end.

141
00:06:33,423 --> 00:06:36,180
So somewhere in the Linux file system,

142
00:06:36,180 --> 00:06:39,700
not your regular windows file system.

143
00:06:39,700 --> 00:06:43,540
Now you might wonder how you get to this Linux file system,

144
00:06:43,540 --> 00:06:44,730
attached you'll find a link.

145
00:06:44,730 --> 00:06:46,440
You find a link to this article,

146
00:06:46,440 --> 00:06:50,700
which explains how you can mount and work

147
00:06:50,700 --> 00:06:53,370
with this Linux file system.

148
00:06:53,370 --> 00:06:56,610
Where if you then have your project in there,

149
00:06:56,610 --> 00:07:00,610
your changes will propagate to the Docker container.

150
00:07:00,610 --> 00:07:03,910
And therefore they should update as shown.

151
00:07:03,910 --> 00:07:07,020
If you use the regular windows file system,

152
00:07:07,020 --> 00:07:11,290
file changes are not propagated to the Docker container,

153
00:07:11,290 --> 00:07:14,660
and therefore not picked up by tools like nodemon.

