1
00:00:02,280 --> 00:00:04,990
So let's use compose here in this project

2
00:00:04,990 --> 00:00:07,120
and you'll find this project attached

3
00:00:07,120 --> 00:00:08,770
and it is the project we built

4
00:00:08,770 --> 00:00:10,790
in the last course section.

5
00:00:10,790 --> 00:00:11,850
So we have a backend

6
00:00:11,850 --> 00:00:12,880
and we have a frontend

7
00:00:12,880 --> 00:00:14,660
and we got the docker files

8
00:00:14,660 --> 00:00:17,180
in the backend and frontend folders.

9
00:00:17,180 --> 00:00:18,020
So did we there

10
00:00:18,020 --> 00:00:20,180
also have these images prepared

11
00:00:20,180 --> 00:00:21,190
because as I mentioned,

12
00:00:21,190 --> 00:00:23,160
we'll need these docker files.

13
00:00:23,160 --> 00:00:26,290
Docker compose will not replace them.

14
00:00:26,290 --> 00:00:29,510
Now, how do we get started with docker compose then?

15
00:00:29,510 --> 00:00:31,460
Well, in your project folder,

16
00:00:31,460 --> 00:00:36,460
you create a docker-compose.yml or yamol file.

17
00:00:37,650 --> 00:00:40,040
The extension can be free or four characters.

18
00:00:40,040 --> 00:00:41,970
It's always a yamol file

19
00:00:41,970 --> 00:00:45,610
and yamol is just a specific text format

20
00:00:45,610 --> 00:00:48,270
where you use indentation

21
00:00:48,270 --> 00:00:50,000
to express dependencies

22
00:00:50,000 --> 00:00:52,040
between configuration options.

23
00:00:52,040 --> 00:00:54,680
You'll see it in action here.

24
00:00:54,680 --> 00:00:57,850
Now, in such a docker compose yamol file,

25
00:00:57,850 --> 00:01:01,080
you describe your multi container environment,

26
00:01:01,080 --> 00:01:02,870
your project setup,

27
00:01:02,870 --> 00:01:06,870
and you always start by defining a version here.

28
00:01:06,870 --> 00:01:09,600
Now you should get auto completion here, by the way,

29
00:01:09,600 --> 00:01:13,150
since we installed the docker extension,

30
00:01:13,150 --> 00:01:13,983
make sure you have

31
00:01:13,983 --> 00:01:15,610
that Docker extension installed

32
00:01:15,610 --> 00:01:16,740
in visual studio code

33
00:01:16,740 --> 00:01:19,450
and with that you will get all the completion here,

34
00:01:19,450 --> 00:01:21,700
which is very helpful.

35
00:01:21,700 --> 00:01:23,640
So we specify a version here

36
00:01:23,640 --> 00:01:26,160
and with version I don't mean a version

37
00:01:26,160 --> 00:01:29,300
for our app or our file here.

38
00:01:29,300 --> 00:01:31,820
Instead, we specify the version

39
00:01:31,820 --> 00:01:35,350
of the docker compose specification we wanna use

40
00:01:35,350 --> 00:01:37,160
and the version we defined here

41
00:01:37,160 --> 00:01:39,510
has an effect on the features

42
00:01:39,510 --> 00:01:41,970
we can use in this compose file

43
00:01:41,970 --> 00:01:44,940
because the docker compose specification

44
00:01:44,940 --> 00:01:47,480
and therefore the Syntex we have

45
00:01:47,480 --> 00:01:49,690
to use in this docker compose file

46
00:01:49,690 --> 00:01:51,430
is under active development

47
00:01:51,430 --> 00:01:53,140
and may change over time.

48
00:01:53,140 --> 00:01:55,810
So you can lock in a certain version up here

49
00:01:55,810 --> 00:01:58,410
so the docker knows which features are

50
00:01:58,410 --> 00:01:59,990
and are not available.

51
00:01:59,990 --> 00:02:01,090
And therefore it's able

52
00:02:01,090 --> 00:02:04,250
to execute your docker compose file correctly.

53
00:02:04,250 --> 00:02:09,250
Now you can visit docs.docker.com/compose/composed-file.

54
00:02:10,880 --> 00:02:13,430
And you will find a complete reference

55
00:02:13,430 --> 00:02:15,230
of all the configuration options

56
00:02:15,230 --> 00:02:17,070
you can set up in a composed file,

57
00:02:17,070 --> 00:02:19,110
and you also find the different

58
00:02:19,110 --> 00:02:21,910
compose specification versions,

59
00:02:21,910 --> 00:02:23,050
which are available.

60
00:02:23,050 --> 00:02:25,810
And obviously that will change over time.

61
00:02:25,810 --> 00:02:28,630
I'm using 3.8 when I'm recording this,

62
00:02:28,630 --> 00:02:30,230
there will be newer versions out

63
00:02:30,230 --> 00:02:31,920
when you're viewing this most likely.

64
00:02:31,920 --> 00:02:33,450
However, of course, a new version

65
00:02:33,450 --> 00:02:35,280
does not mean that everything changed

66
00:02:35,280 --> 00:02:37,620
maybe some tiny new features were added

67
00:02:37,620 --> 00:02:38,870
and to be honest,

68
00:02:38,870 --> 00:02:40,690
most of the features you can use

69
00:02:40,690 --> 00:02:42,960
most of the configurations you can add

70
00:02:42,960 --> 00:02:46,250
might not matter to your project.

71
00:02:46,250 --> 00:02:47,390
And that's an evernote

72
00:02:47,390 --> 00:02:49,650
I have about this site here.

73
00:02:49,650 --> 00:02:51,140
It's a huge list,

74
00:02:51,140 --> 00:02:54,040
a long list of configuration options

75
00:02:54,040 --> 00:02:56,950
you can add in your docker compose yamol file

76
00:02:56,950 --> 00:02:59,030
and you will not need all of them.

77
00:02:59,030 --> 00:03:01,290
You will only need a small subset

78
00:03:01,290 --> 00:03:03,130
for most applications

79
00:03:03,130 --> 00:03:03,963
but of course,

80
00:03:03,963 --> 00:03:06,700
in order to express any potential projects

81
00:03:06,700 --> 00:03:08,041
that you might have,

82
00:03:08,041 --> 00:03:11,080
you have a lot of configuration options here.

83
00:03:11,080 --> 00:03:13,380
Now you can use this as a backup reference.

84
00:03:13,380 --> 00:03:16,280
I just wanted to talk about these versions.

85
00:03:16,280 --> 00:03:17,840
And so they offer at the moment

86
00:03:17,840 --> 00:03:20,980
3.8 is the latest version I have available.

87
00:03:20,980 --> 00:03:23,020
And I will specify this here

88
00:03:23,020 --> 00:03:25,140
therefore, to inform docker

89
00:03:25,140 --> 00:03:27,560
that this is the version does file uses

90
00:03:27,560 --> 00:03:28,990
and to let docker know

91
00:03:28,990 --> 00:03:31,690
which features I therefore want to use

92
00:03:31,690 --> 00:03:33,563
and want to be able to use.

93
00:03:35,090 --> 00:03:39,320
So that is the first thing we have to add, the version,

94
00:03:39,320 --> 00:03:41,210
that next thing,

95
00:03:41,210 --> 00:03:43,640
the next configuration we have to add here

96
00:03:43,640 --> 00:03:46,090
is the services key

97
00:03:46,090 --> 00:03:47,270
And by the way,

98
00:03:47,270 --> 00:03:48,890
these key names of course

99
00:03:48,890 --> 00:03:50,630
have to be typed correctly

100
00:03:50,630 --> 00:03:53,560
because docker will look out for these keywords.

101
00:03:53,560 --> 00:03:55,220
So this has to be version

102
00:03:55,220 --> 00:03:57,460
and not Version like this

103
00:03:57,460 --> 00:03:59,370
or VRS like this.

104
00:03:59,370 --> 00:04:01,730
It has to be written exactly like that.

105
00:04:01,730 --> 00:04:03,490
That's why it is auto-completion

106
00:04:03,490 --> 00:04:05,870
with the docker extension helps.

107
00:04:05,870 --> 00:04:07,360
So here we got services

108
00:04:07,360 --> 00:04:10,970
and now services doesn't take a value like this.

109
00:04:10,970 --> 00:04:14,830
Instead it has a couple of nested values.

110
00:04:14,830 --> 00:04:16,649
So we enter a new line

111
00:04:16,649 --> 00:04:19,589
and now the indentation here matters.

112
00:04:19,589 --> 00:04:23,260
I did indent by two blanks here.

113
00:04:23,260 --> 00:04:24,570
And this is important

114
00:04:24,570 --> 00:04:27,180
because yamol uses indentation

115
00:04:27,180 --> 00:04:29,340
to express dependencies

116
00:04:29,340 --> 00:04:32,550
and everything which is indented by two blanks

117
00:04:32,550 --> 00:04:36,190
is now a direct child of services

118
00:04:36,190 --> 00:04:38,000
and services needs

119
00:04:38,000 --> 00:04:40,270
at least one child element

120
00:04:40,270 --> 00:04:43,310
possibly multiple children.

121
00:04:43,310 --> 00:04:46,150
Now what are the children of services though?

122
00:04:46,150 --> 00:04:48,420
That will be your containers.

123
00:04:48,420 --> 00:04:50,610
And since our application here

124
00:04:50,610 --> 00:04:52,410
has three containers,

125
00:04:52,410 --> 00:04:57,140
we will have three child elements here below services.

126
00:04:57,140 --> 00:04:58,750
Now you can choose names

127
00:04:58,750 --> 00:05:01,840
of your choice to label these containers

128
00:05:01,840 --> 00:05:04,610
to give these containers a name.

129
00:05:04,610 --> 00:05:08,303
And I will name one container backend,

130
00:05:09,150 --> 00:05:11,910
one container frontend,

131
00:05:11,910 --> 00:05:15,700
and maybe first one container mongodb.

132
00:05:15,700 --> 00:05:18,290
Now these names are up to you.

133
00:05:18,290 --> 00:05:20,410
You can use any names you want here.

134
00:05:20,410 --> 00:05:22,720
They should all be on the same level though.

135
00:05:22,720 --> 00:05:25,120
All indented by two blanks,

136
00:05:25,120 --> 00:05:29,143
since they all are equal children to services.

137
00:05:30,080 --> 00:05:31,420
With that we're defining

138
00:05:31,420 --> 00:05:34,270
that our application, our project

139
00:05:34,270 --> 00:05:36,333
will use three containers.

140
00:05:37,510 --> 00:05:39,200
Now of course that's just the start.

141
00:05:39,200 --> 00:05:41,660
Now we can define a configuration

142
00:05:41,660 --> 00:05:43,440
for every container

143
00:05:43,440 --> 00:05:45,400
and you might already be guessing it.

144
00:05:45,400 --> 00:05:48,250
We do that by indenting again.

145
00:05:48,250 --> 00:05:51,690
So now I indent here below mongodb

146
00:05:51,690 --> 00:05:52,850
to set up the options

147
00:05:52,850 --> 00:05:55,030
that belong to the mongodb container.

148
00:05:55,030 --> 00:05:56,390
And we'll do something similar

149
00:05:56,390 --> 00:05:58,750
for backend and for frontend

150
00:05:58,750 --> 00:06:01,590
we'll indent by two more blanks here.

151
00:06:01,590 --> 00:06:03,660
So four blanks in total,

152
00:06:03,660 --> 00:06:05,300
and then that's the configuration

153
00:06:05,300 --> 00:06:08,180
for mongodb, backend and so on.

154
00:06:08,180 --> 00:06:09,800
So that's what we'll continue with

155
00:06:09,800 --> 00:06:12,940
because now we can dive into the configurations

156
00:06:12,940 --> 00:06:15,163
for the individual containers.

