1
00:00:02,250 --> 00:00:04,540
Using Docker and containers

2
00:00:04,540 --> 00:00:07,070
offers us various advantages.

3
00:00:07,070 --> 00:00:11,270
We talked about this in the first course section already.

4
00:00:11,270 --> 00:00:13,060
Now, up to this point,

5
00:00:13,060 --> 00:00:16,610
we can see one advantage in action already.

6
00:00:16,610 --> 00:00:18,360
We don't have to uninstall

7
00:00:18,360 --> 00:00:21,630
and re-install local dependencies all the time.

8
00:00:21,630 --> 00:00:25,260
Instead, we are already using Docker for example,

9
00:00:25,260 --> 00:00:27,610
in our assignment applications,

10
00:00:27,610 --> 00:00:31,040
but also in the applications we built before that,

11
00:00:31,040 --> 00:00:32,369
in this module.

12
00:00:32,369 --> 00:00:34,670
We're using Docker to install

13
00:00:34,670 --> 00:00:37,950
the dependencies of this node app inside of the image

14
00:00:37,950 --> 00:00:39,630
and container therefore,

15
00:00:39,630 --> 00:00:42,200
and we therefore don't have to install node

16
00:00:42,200 --> 00:00:44,640
globally on our system either.

17
00:00:44,640 --> 00:00:46,840
I happen to have it installed,

18
00:00:46,840 --> 00:00:49,010
but we wouldn't need that.

19
00:00:49,010 --> 00:00:50,700
And the same for Python.

20
00:00:50,700 --> 00:00:53,230
Thanks to Docker, which we use here.

21
00:00:53,230 --> 00:00:57,060
We don't need to install Python globally on our system,

22
00:00:57,060 --> 00:00:59,833
it's in the image and container instead.

23
00:01:00,860 --> 00:01:04,310
And even if that would be all we're using Docker for,

24
00:01:04,310 --> 00:01:06,410
that would already be great.

25
00:01:06,410 --> 00:01:07,850
because it would allow us

26
00:01:07,850 --> 00:01:11,200
to have multiple projects on our computer

27
00:01:11,200 --> 00:01:15,000
with different dependencies and different versions,

28
00:01:15,000 --> 00:01:18,410
and they could co-exist side by side

29
00:01:18,410 --> 00:01:20,620
without us having to uninstall

30
00:01:20,620 --> 00:01:23,830
or re-install various tools all the time.

31
00:01:23,830 --> 00:01:26,940
We could have a Python 3.7 based app

32
00:01:26,940 --> 00:01:30,170
next to a Python 3.9 based app

33
00:01:30,170 --> 00:01:33,130
without switching python versions in between.

34
00:01:33,130 --> 00:01:35,260
So that's great already.

35
00:01:35,260 --> 00:01:37,900
Still, this is not the only reason

36
00:01:37,900 --> 00:01:40,150
why we're typically using Docker.

37
00:01:40,150 --> 00:01:43,240
We're also using it to share our images

38
00:01:43,240 --> 00:01:45,210
and containers with others.

39
00:01:45,210 --> 00:01:47,170
That could be team members

40
00:01:47,170 --> 00:01:50,010
who are working on the same project,

41
00:01:50,010 --> 00:01:51,830
or that could be servers

42
00:01:51,830 --> 00:01:54,563
on which we wanna deploy our containers.

43
00:01:55,410 --> 00:01:57,950
Now I'll dive into deployment later

44
00:01:57,950 --> 00:02:00,670
since that involves a couple of steps,

45
00:02:00,670 --> 00:02:03,130
but I wanna start with sharing images

46
00:02:03,130 --> 00:02:05,320
and containers with other persons,

47
00:02:05,320 --> 00:02:10,320
or even with ourselves on different machines right now.

48
00:02:10,320 --> 00:02:13,690
Because there's one simple thing we have to keep in mind,

49
00:02:13,690 --> 00:02:15,690
everyone who has an image,

50
00:02:15,690 --> 00:02:19,670
can create containers based on that image.

51
00:02:19,670 --> 00:02:21,130
So that of course also means

52
00:02:21,130 --> 00:02:24,500
that we don't really share containers with anyone,

53
00:02:24,500 --> 00:02:27,270
instead, we'll share images.

54
00:02:27,270 --> 00:02:28,870
Because if you have an image,

55
00:02:28,870 --> 00:02:31,453
you can run a container based on that image.

56
00:02:32,460 --> 00:02:34,790
I mean, that's all to what we did before.

57
00:02:34,790 --> 00:02:37,060
We're building up our own images

58
00:02:37,060 --> 00:02:39,830
on the Python or node images.

59
00:02:39,830 --> 00:02:42,770
So we're also pulling down these images

60
00:02:42,770 --> 00:02:45,330
from Docker hub as I showed you earlier,

61
00:02:45,330 --> 00:02:49,150
and then we're able to use them to run our own containers,

62
00:02:49,150 --> 00:02:51,950
which in the end are also based on those images,

63
00:02:51,950 --> 00:02:53,610
at least partly.

64
00:02:53,610 --> 00:02:55,650
And when it comes to sharing images,

65
00:02:55,650 --> 00:02:58,570
we've got two main ways of doing that.

66
00:02:58,570 --> 00:03:00,583
We can share the Dockerfile.

67
00:03:02,550 --> 00:03:05,340
If I give you that Dockerfile

68
00:03:05,340 --> 00:03:08,600
and the source code that belongs to this application,

69
00:03:08,600 --> 00:03:10,260
you can build your own image

70
00:03:10,260 --> 00:03:12,920
and use that to run a container.

71
00:03:12,920 --> 00:03:15,420
And that's actually how the various

72
00:03:15,420 --> 00:03:19,000
code snapshot attachments you'll find in this course

73
00:03:19,000 --> 00:03:20,260
are organized.

74
00:03:20,260 --> 00:03:23,650
If you find an attachment on one of the lectures

75
00:03:23,650 --> 00:03:26,780
it's a SIPP file, which contains a Dockerfile

76
00:03:26,780 --> 00:03:30,490
and then the code belonging to that Dockerfile.

77
00:03:30,490 --> 00:03:32,890
And then you can build that image on your own

78
00:03:32,890 --> 00:03:35,330
and run container based on it.

79
00:03:35,330 --> 00:03:37,380
Now that's one way of sharing an image.

80
00:03:37,380 --> 00:03:39,540
I simply give you the Dockerfile

81
00:03:39,540 --> 00:03:41,240
and you're good to go.

82
00:03:41,240 --> 00:03:42,360
But that's, for example

83
00:03:42,360 --> 00:03:46,060
not what's happening when we're basing this image

84
00:03:46,060 --> 00:03:47,930
on the node image.

85
00:03:47,930 --> 00:03:51,870
We're not downloading the node Dockerfile anywhere.

86
00:03:51,870 --> 00:03:55,053
I never built the node image myself.

87
00:03:55,990 --> 00:03:58,810
And just to make this super clear,

88
00:03:58,810 --> 00:04:01,490
if you Google for GitHub node Docker,

89
00:04:01,490 --> 00:04:06,490
you find the official repository for the Docker node image.

90
00:04:06,630 --> 00:04:11,630
And in there, you will actually also find Dockerfiles.

91
00:04:11,650 --> 00:04:14,350
For example, for the 14 tag,

92
00:04:14,350 --> 00:04:18,560
let's say therefore this alpine version whatever,

93
00:04:18,560 --> 00:04:20,579
there you find a Dockerfile

94
00:04:20,579 --> 00:04:23,380
which in the end sets up this node image.

95
00:04:23,380 --> 00:04:27,770
It's based on alpine which is a Linux distribution.

96
00:04:27,770 --> 00:04:31,230
So it's the operating system for this node image so to say,

97
00:04:31,230 --> 00:04:34,570
and then it has various instructions in here

98
00:04:34,570 --> 00:04:38,700
obviously more complex instructions than in our basic image

99
00:04:38,700 --> 00:04:43,433
which do configure this image to set up a node environment.

100
00:04:44,320 --> 00:04:48,530
And this is the kind of image we are basing our image on

101
00:04:48,530 --> 00:04:50,753
if we're using the from instruction.

102
00:04:51,610 --> 00:04:53,540
But again, we didn't download

103
00:04:53,540 --> 00:04:55,360
and built the Dockerfile,

104
00:04:55,360 --> 00:04:58,750
instead, we just used this image like this.

105
00:04:58,750 --> 00:05:01,030
Also earlier in this course,

106
00:05:01,030 --> 00:05:03,940
when I executed docker run node,

107
00:05:03,940 --> 00:05:06,580
referring to that official node image.

108
00:05:06,580 --> 00:05:08,560
This also works.

109
00:05:08,560 --> 00:05:11,110
It downloads the latest note image

110
00:05:11,110 --> 00:05:13,783
and then just runs it as a container.

111
00:05:14,620 --> 00:05:16,750
In this case, it stops automatically

112
00:05:16,750 --> 00:05:20,060
since I didn't add an interactive session to the image

113
00:05:20,060 --> 00:05:21,430
but that doesn't matter here.

114
00:05:21,430 --> 00:05:25,330
The key takeaway is that here we didn't get a Dockerfile,

115
00:05:25,330 --> 00:05:26,713
which we built on our own.

116
00:05:28,880 --> 00:05:32,770
Because there always is a second way of sharing images

117
00:05:32,770 --> 00:05:34,800
besides sharing a Dockerfile

118
00:05:34,800 --> 00:05:38,420
and leaving it up to the recipient to build that Dockerfile,

119
00:05:38,420 --> 00:05:42,350
you can also share a complete built image.

120
00:05:42,350 --> 00:05:44,970
So not the Dockerfile, but the finished image.

121
00:05:44,970 --> 00:05:46,603
You can share this too.

122
00:05:47,660 --> 00:05:49,360
Now, when you get a Dockerfile,

123
00:05:49,360 --> 00:05:50,600
you have to build it

124
00:05:50,600 --> 00:05:53,260
and your therefore also need all the surrounding code

125
00:05:53,260 --> 00:05:56,250
and folder structure that should go into the image.

126
00:05:56,250 --> 00:05:59,790
If you get the image, you just download the image

127
00:05:59,790 --> 00:06:02,440
and you can run a container instantly.

128
00:06:02,440 --> 00:06:03,880
You don't need to build it

129
00:06:03,880 --> 00:06:07,810
and you don't need any extra code or surrounding folders.

130
00:06:07,810 --> 00:06:10,050
So there's no build step required here.

131
00:06:10,050 --> 00:06:13,110
Everything is included in the image already.

132
00:06:13,110 --> 00:06:14,870
And therefore that's how you typically

133
00:06:14,870 --> 00:06:17,450
share images with other people.

134
00:06:17,450 --> 00:06:19,890
Now, in the course I stick to these attachments

135
00:06:19,890 --> 00:06:22,630
with the raw code so that you can compare

136
00:06:22,630 --> 00:06:24,410
that to your code as well.

137
00:06:24,410 --> 00:06:27,010
But if you share it with a team member

138
00:06:27,010 --> 00:06:29,420
or also later for deployment,

139
00:06:29,420 --> 00:06:32,570
you typically work with finished images

140
00:06:32,570 --> 00:06:34,873
and not with raw Dockerfiles.

