1
00:00:01,437 --> 00:00:04,890
So we created our first Dockerfile.

2
00:00:04,890 --> 00:00:08,820
Therefore, we then also built our first custom image

3
00:00:08,820 --> 00:00:13,820
and we ran the first container based on a custom image.

4
00:00:13,820 --> 00:00:15,210
Now, there is way more

5
00:00:15,210 --> 00:00:19,210
which we can and will learn about this Dockerfile

6
00:00:19,210 --> 00:00:21,210
and also about the Docker command

7
00:00:21,210 --> 00:00:24,100
and all the subcommands we can run there.

8
00:00:24,100 --> 00:00:26,960
All the different ways of configuring things.

9
00:00:26,960 --> 00:00:29,143
We are going to explore that.

10
00:00:30,010 --> 00:00:33,940
But before we explore anything related to that,

11
00:00:33,940 --> 00:00:36,850
it is important that we fully understand

12
00:00:36,850 --> 00:00:39,430
how an image and a container work

13
00:00:39,430 --> 00:00:40,780
and how they work together.

14
00:00:41,660 --> 00:00:46,250
And for that, let's say in our Node application code,

15
00:00:46,250 --> 00:00:48,360
we wanna change that code.

16
00:00:48,360 --> 00:00:50,590
We wanna change that code and say

17
00:00:50,590 --> 00:00:55,430
My Course Goal! Here for example.

18
00:00:55,430 --> 00:00:59,640
This is a tiny change made to this HTML code

19
00:00:59,640 --> 00:01:04,453
which now should be reflected in our running application.

20
00:01:06,200 --> 00:01:10,330
So if I rerun this command to restart this container

21
00:01:10,330 --> 00:01:12,980
based on this image, which we built,

22
00:01:12,980 --> 00:01:17,040
the application, the Node application starts again.

23
00:01:17,040 --> 00:01:19,880
And if I now reload localhost 3000

24
00:01:19,880 --> 00:01:22,400
I see this application again.

25
00:01:22,400 --> 00:01:25,340
But we also see one problem.

26
00:01:25,340 --> 00:01:28,893
My little change in code isn't reflected here.

27
00:01:29,810 --> 00:01:32,430
Keep in mind, I added an exclamation mark

28
00:01:32,430 --> 00:01:34,183
after My Course Goal.

29
00:01:35,780 --> 00:01:39,120
Here, we still see My Course Goal like this

30
00:01:39,120 --> 00:01:41,420
without the exclamation mark.

31
00:01:41,420 --> 00:01:44,010
So, why is this change not reflected?

32
00:01:44,010 --> 00:01:48,190
I mean, I even restarted the container in the meantime.

33
00:01:48,190 --> 00:01:50,430
In case you didn't do that by the way,

34
00:01:50,430 --> 00:01:52,310
you learned that with docker PS

35
00:01:52,310 --> 00:01:56,600
you can see running containers, then you can pick the name

36
00:01:56,600 --> 00:02:00,700
and run docker stop to stop it and then restart it.

37
00:02:00,700 --> 00:02:03,740
But again, that restarting didn't do anything here.

38
00:02:03,740 --> 00:02:07,393
I don't see that change in my web application.

39
00:02:08,449 --> 00:02:12,080
Because we have to understand how images work,

40
00:02:12,080 --> 00:02:15,430
keep in mind that this is part of our source code,

41
00:02:15,430 --> 00:02:17,900
our Node application code.

42
00:02:17,900 --> 00:02:20,520
What are we doing with that code?

43
00:02:20,520 --> 00:02:24,250
Well, in the Docker file, we instruct Docker,

44
00:02:24,250 --> 00:02:28,960
to in the end, copy everything inside of this project folder

45
00:02:28,960 --> 00:02:32,920
including the server.js file, which holds my source code

46
00:02:32,920 --> 00:02:36,090
into the container file system to be precise

47
00:02:36,090 --> 00:02:38,610
into the app folder.

48
00:02:38,610 --> 00:02:40,500
Then we run npm install,

49
00:02:40,500 --> 00:02:43,550
tell Docker that it should open up port 80

50
00:02:43,550 --> 00:02:46,923
and start the server when the container is launched.

51
00:02:48,020 --> 00:02:50,710
Now, therefore we do one important thing.

52
00:02:50,710 --> 00:02:54,610
We copy our source code into the image,

53
00:02:54,610 --> 00:02:59,000
and we basically take a snapshot of our source code

54
00:02:59,000 --> 00:03:00,943
at the point of time we copied.

55
00:03:01,870 --> 00:03:04,870
If I thereafter edit my source code,

56
00:03:04,870 --> 00:03:08,800
as I did it here when I added this exclamation mark,

57
00:03:08,800 --> 00:03:12,820
this change is not part of the source code in the image.

58
00:03:12,820 --> 00:03:17,820
We need to rebuild our image to copy our updated source code

59
00:03:18,370 --> 00:03:20,750
into a new image.

60
00:03:20,750 --> 00:03:22,750
And that is really crucial.

61
00:03:22,750 --> 00:03:26,160
Now, if this sounds cumbersome and strange

62
00:03:26,160 --> 00:03:28,380
that we have to rebuild our image

63
00:03:28,380 --> 00:03:30,400
every time we change our code,

64
00:03:30,400 --> 00:03:32,100
I have a good message for you.

65
00:03:32,100 --> 00:03:35,220
We will find a more elegant and faster way

66
00:03:35,220 --> 00:03:37,703
of picking up changes in our code later.

67
00:03:38,750 --> 00:03:41,620
But the core takeaway here is important

68
00:03:41,620 --> 00:03:43,680
and will always be true.

69
00:03:43,680 --> 00:03:47,870
Images are basically locked and finished

70
00:03:47,870 --> 00:03:49,640
once you built them.

71
00:03:49,640 --> 00:03:53,350
Everything in the images is read only then,

72
00:03:53,350 --> 00:03:56,090
and you can't edit it from the outside

73
00:03:56,090 --> 00:03:58,110
by simply updating your code

74
00:03:58,110 --> 00:04:01,780
just because you copied that code in the past.

75
00:04:01,780 --> 00:04:04,010
The image doesn't care about the past.

76
00:04:04,010 --> 00:04:06,250
Once this copy operation is done,

77
00:04:06,250 --> 00:04:09,340
you can change your outside code however you want.

78
00:04:09,340 --> 00:04:10,590
You can even delete it

79
00:04:10,590 --> 00:04:13,350
and the image will not be affected.

80
00:04:13,350 --> 00:04:17,540
You need to rebuild to pick up external changes

81
00:04:17,540 --> 00:04:21,363
and basically copy all the updated code into the image.

82
00:04:22,310 --> 00:04:23,143
So therefore,

83
00:04:23,143 --> 00:04:24,310
what we need to do here

84
00:04:24,310 --> 00:04:27,770
is we need to run docker build dot again

85
00:04:27,770 --> 00:04:29,550
to rebuild this image

86
00:04:29,550 --> 00:04:32,203
and therefore to build a new image in the end.

87
00:04:33,990 --> 00:04:36,110
So, let's wait for this operation to finish.

88
00:04:36,110 --> 00:04:37,880
And once we get this new image,

89
00:04:37,880 --> 00:04:39,720
we also got a new image name,

90
00:04:39,720 --> 00:04:43,420
because it now really is a totally new image.

91
00:04:43,420 --> 00:04:45,520
It's almost the same as the previous one,

92
00:04:45,520 --> 00:04:47,570
but technically it's totally different.

93
00:04:47,570 --> 00:04:49,943
It has totally different code inside of it.

94
00:04:51,920 --> 00:04:54,660
And we can now docker run this new image

95
00:04:54,660 --> 00:04:56,663
by using this new image name.

96
00:04:57,600 --> 00:05:01,840
And if we do this now and we reload localhost 3000,

97
00:05:01,840 --> 00:05:04,510
you now see the exclamation mark is there

98
00:05:04,510 --> 00:05:06,840
and this change has now been picked up.

99
00:05:06,840 --> 00:05:08,920
Because we rebuilt a new image

100
00:05:08,920 --> 00:05:10,733
with our new code inside of it.

101
00:05:13,100 --> 00:05:14,960
And I'm putting so much emphasis on that,

102
00:05:14,960 --> 00:05:18,420
because it is super crucial to understand

103
00:05:18,420 --> 00:05:23,420
that an image is really a closed template in the end.

104
00:05:23,480 --> 00:05:26,920
These instructions are executed to create the image,

105
00:05:26,920 --> 00:05:29,350
and thereafter it's locked, it's finished.

106
00:05:29,350 --> 00:05:31,460
And if you change something which you copied

107
00:05:31,460 --> 00:05:34,983
into your image thereafter, that has no impact.

108
00:05:36,370 --> 00:05:37,820
So with that all,

109
00:05:37,820 --> 00:05:42,690
also stop this newly created Docker container here.

110
00:05:42,690 --> 00:05:45,370
And we can now dive a bit deeper into images

111
00:05:45,370 --> 00:05:47,010
and again, also containers.

112
00:05:47,010 --> 00:05:49,793
Because there is more which we need to explore here.

