1
00:00:02,130 --> 00:00:04,500
Now, obviously docker-compose is a very,

2
00:00:04,500 --> 00:00:06,140
very useful tool.

3
00:00:06,140 --> 00:00:08,720
And docker-compose up and down,

4
00:00:08,720 --> 00:00:11,123
will be our best friends when working with it.

5
00:00:11,960 --> 00:00:14,450
Now, there are two other commands

6
00:00:14,450 --> 00:00:16,059
or variations of commands,

7
00:00:16,059 --> 00:00:17,030
which I want to show you.

8
00:00:17,030 --> 00:00:19,590
And there's one other thing about the naming

9
00:00:19,590 --> 00:00:22,420
of these containers and services.

10
00:00:22,420 --> 00:00:25,810
Now let me start with the commons.

11
00:00:25,810 --> 00:00:29,610
We saw docker-compose up and down in action.

12
00:00:29,610 --> 00:00:31,930
Now for the up command,

13
00:00:31,930 --> 00:00:33,780
we can also use dash dash help.

14
00:00:33,780 --> 00:00:36,840
We can use this on all Docker-related commands,

15
00:00:36,840 --> 00:00:39,770
although just on docker-compose,

16
00:00:39,770 --> 00:00:40,910
but on the up command,

17
00:00:40,910 --> 00:00:44,020
I want to use it because there's one specific option,

18
00:00:44,020 --> 00:00:45,950
which we can set, which is interesting.

19
00:00:45,950 --> 00:00:48,513
And that's the dash dash build option.

20
00:00:49,440 --> 00:00:53,700
With the dash dash build option add it to the up command,

21
00:00:53,700 --> 00:00:57,670
you force that images are rebuilt.

22
00:00:57,670 --> 00:01:00,770
Otherwise, images like this backend image here,

23
00:01:00,770 --> 00:01:04,010
which we do build based on our own Docker file,

24
00:01:04,010 --> 00:01:05,950
will only be built once.

25
00:01:05,950 --> 00:01:09,200
And if docker-composed then finds this image,

26
00:01:09,200 --> 00:01:13,050
the next time it tries to start all these services,

27
00:01:13,050 --> 00:01:16,110
it will reuse the existing image.

28
00:01:16,110 --> 00:01:17,760
This might be what you want

29
00:01:17,760 --> 00:01:20,700
and often it will not be a problem at all,

30
00:01:20,700 --> 00:01:23,520
but if you want to force it to rebuild it,

31
00:01:23,520 --> 00:01:26,120
because for example, you know that something changed

32
00:01:26,120 --> 00:01:29,460
in code and therefore a new image should be built,

33
00:01:29,460 --> 00:01:34,273
then you can force docker-compose by adding dash dash build.

34
00:01:35,180 --> 00:01:38,640
Now, if you just want to build the images defined

35
00:01:38,640 --> 00:01:40,900
in your docker-compose file,

36
00:01:40,900 --> 00:01:43,360
and with that I'm of course only referring

37
00:01:43,360 --> 00:01:46,710
to the images we build with the build key here,

38
00:01:46,710 --> 00:01:49,440
not to images you point at with image,

39
00:01:49,440 --> 00:01:52,810
these are images you are pulling from Docker Hub

40
00:01:52,810 --> 00:01:54,600
or from some other registry

41
00:01:54,600 --> 00:01:57,300
and therefore they are already build.

42
00:01:57,300 --> 00:01:58,720
But for your own images,

43
00:01:58,720 --> 00:02:01,430
if you just want to build any custom images

44
00:02:01,430 --> 00:02:03,910
to find in a docker-compose file,

45
00:02:03,910 --> 00:02:06,973
you can do that with docker-compose build.

46
00:02:07,820 --> 00:02:11,380
Now, when you run up, the build step is included.

47
00:02:11,380 --> 00:02:13,200
If a image needs to be built

48
00:02:13,200 --> 00:02:16,620
in order to start the container, it will be built.

49
00:02:16,620 --> 00:02:18,100
But if you just want to build,

50
00:02:18,100 --> 00:02:20,480
without starting a container thereafter,

51
00:02:20,480 --> 00:02:24,200
you could trigger this by running docker-compose build,

52
00:02:24,200 --> 00:02:26,760
and now it will really just do that,

53
00:02:26,760 --> 00:02:31,680
build any missing images and then not start containers.

54
00:02:31,680 --> 00:02:34,200
Just build the images.

55
00:02:34,200 --> 00:02:39,060
Now, thereafter of course, if I run docker-compose up

56
00:02:39,060 --> 00:02:43,733
in detached mode, for example, it starts these services,

57
00:02:43,733 --> 00:02:47,000
it downloads any images that might be missing.

58
00:02:47,000 --> 00:02:50,240
In my case, I deleted the Mongo image off screen

59
00:02:50,240 --> 00:02:52,580
and therefore it re-downloads this,

60
00:02:52,580 --> 00:02:56,260
but it should not rebuild the back-end image, for example,

61
00:02:56,260 --> 00:02:58,996
because we just built this and as explained a couple

62
00:02:58,996 --> 00:03:02,510
of minutes ago, docker-compose will only check

63
00:03:02,510 --> 00:03:04,890
if an image is there locally

64
00:03:04,890 --> 00:03:08,343
and if it is it will use that and not recreate it.

65
00:03:09,340 --> 00:03:11,234
Now, I also got one last note here,

66
00:03:11,234 --> 00:03:14,290
and this is related to the names of the containers,

67
00:03:14,290 --> 00:03:16,470
which are created and started.

68
00:03:16,470 --> 00:03:20,800
You can of course see them if you run the Docker PS command.

69
00:03:20,800 --> 00:03:22,900
You see, we have that running front-end,

70
00:03:22,900 --> 00:03:25,760
back-end and Mongo container.

71
00:03:25,760 --> 00:03:28,370
And you can see their names as well.

72
00:03:28,370 --> 00:03:32,800
The front-end container was named docker-complete_front_1.

73
00:03:32,800 --> 00:03:34,540
Here's the name of the backend

74
00:03:34,540 --> 00:03:37,440
and here's the name of the Mongo Db container.

75
00:03:37,440 --> 00:03:38,770
Now, what you will notice,

76
00:03:38,770 --> 00:03:42,640
is that these are not the names we defined

77
00:03:42,640 --> 00:03:44,150
in docker-compose.

78
00:03:44,150 --> 00:03:48,310
There I specified Mongo Db and back-end

79
00:03:48,310 --> 00:03:51,263
and front-end as names.

80
00:03:52,300 --> 00:03:55,660
Well, technically these are just the service names

81
00:03:55,660 --> 00:03:58,280
and they are translated to containers,

82
00:03:58,280 --> 00:04:00,990
but these are not the container names therefore.

83
00:04:00,990 --> 00:04:04,920
These names are just picked up in the container names.

84
00:04:04,920 --> 00:04:08,903
You see that Mongo Db is part of this last name.

85
00:04:09,840 --> 00:04:13,100
The full name is actually your folder name,

86
00:04:13,100 --> 00:04:15,050
your project folder name,

87
00:04:15,050 --> 00:04:16,380
then an underscore,

88
00:04:16,380 --> 00:04:18,709
then your service name,

89
00:04:18,709 --> 00:04:21,579
and then an incrementing number.

90
00:04:21,579 --> 00:04:25,000
Now, if you wanna assign your own container name,

91
00:04:25,000 --> 00:04:29,710
you can do this by adding the container name option here.

92
00:04:29,710 --> 00:04:32,240
And if I would set this to Mongo DB here,

93
00:04:32,240 --> 00:04:36,350
now I would force this name of the actual container,

94
00:04:36,350 --> 00:04:39,350
which is up and running to be Mongo Db.

95
00:04:39,350 --> 00:04:42,223
So if I now run docker-compose down,

96
00:04:43,580 --> 00:04:47,590
and then we run docker-compose up again,

97
00:04:47,590 --> 00:04:49,660
you will notice that now,

98
00:04:49,660 --> 00:04:51,750
if I run Docker PS,

99
00:04:51,750 --> 00:04:56,533
this Mongo Db container really has a name of Mongo Db.

100
00:04:57,760 --> 00:05:00,160
Now, I will remove this because I am fine

101
00:05:00,160 --> 00:05:02,230
with the auto-generated names,

102
00:05:02,230 --> 00:05:03,800
I just want to show this to you,

103
00:05:03,800 --> 00:05:07,030
so that you know that you can change these names.

104
00:05:07,030 --> 00:05:09,140
But that's it with docker-compose for now,

105
00:05:09,140 --> 00:05:10,860
it's a very powerful tool

106
00:05:10,860 --> 00:05:14,570
and it allows us to build multi-container applications

107
00:05:14,570 --> 00:05:16,263
on our local host machine

108
00:05:16,263 --> 00:05:19,520
and start and control all the containers

109
00:05:19,520 --> 00:05:23,283
together with one command and one conflict file.

