1
00:00:02,110 --> 00:00:03,710
And now the question is,

2
00:00:03,710 --> 00:00:07,880
how do we start services with docker-compose?

3
00:00:07,880 --> 00:00:10,860
To start services with docker-compose,

4
00:00:10,860 --> 00:00:13,040
we of course need the terminal,

5
00:00:13,040 --> 00:00:15,000
navigated into the folder where

6
00:00:15,000 --> 00:00:16,930
this docker-compose file sits,

7
00:00:16,930 --> 00:00:19,400
so navigated into your project,

8
00:00:19,400 --> 00:00:22,450
and now it's just one command.

9
00:00:22,450 --> 00:00:24,840
docker-compose up.

10
00:00:24,840 --> 00:00:26,920
And this will start all the services

11
00:00:26,920 --> 00:00:28,800
to find in this compose file.

12
00:00:28,800 --> 00:00:31,170
And it will not just start the containers,

13
00:00:31,170 --> 00:00:32,941
it also will pull and build

14
00:00:32,941 --> 00:00:36,050
all the images that might be required.

15
00:00:36,050 --> 00:00:37,970
And to show this as well,

16
00:00:37,970 --> 00:00:41,200
I'll also run docker image prune,

17
00:00:41,200 --> 00:00:45,430
to remove all images, actually docker image prune-a,

18
00:00:45,430 --> 00:00:47,623
to really remove all images,

19
00:00:48,980 --> 00:00:52,370
so that I clear all images I have on my system,

20
00:00:52,370 --> 00:00:54,750
so that I start from scratch again,

21
00:00:54,750 --> 00:00:57,330
I'll also run docker container prune,

22
00:00:57,330 --> 00:00:59,383
to remove all stopped containers,

23
00:01:00,290 --> 00:01:04,030
and now let's make sure we have no running container either,

24
00:01:04,030 --> 00:01:05,160
That looks good.

25
00:01:05,160 --> 00:01:07,770
So with that all cleared and cleaned up,

26
00:01:07,770 --> 00:01:11,040
we can now run Docker-compose up,

27
00:01:11,040 --> 00:01:14,610
and hit Enter, And now this does all the setup work

28
00:01:14,610 --> 00:01:16,190
that is required.

29
00:01:16,190 --> 00:01:18,410
And if we scroll up a bit,

30
00:01:18,410 --> 00:01:20,100
got quite a bit of output here.

31
00:01:20,100 --> 00:01:22,510
If we scroll up quite a bit,

32
00:01:22,510 --> 00:01:25,480
we can see that here I ran docker-compose up,

33
00:01:25,480 --> 00:01:29,617
then it created a network docker-complete default,

34
00:01:29,617 --> 00:01:32,690
and so it takes your project folder name,

35
00:01:32,690 --> 00:01:35,460
in my case that is docker-complete,

36
00:01:35,460 --> 00:01:39,460
and then attaches underscore default here,

37
00:01:39,460 --> 00:01:41,250
So it creates that network,

38
00:01:41,250 --> 00:01:43,800
It creates the data volume,

39
00:01:43,800 --> 00:01:46,970
naming it "Docker-complete_data" though .

40
00:01:46,970 --> 00:01:50,853
So this is all prefixed by your project folder name,

41
00:01:51,920 --> 00:01:54,500
and then starts listening to that service.

42
00:01:54,500 --> 00:01:57,970
So by default, it starts in attached mode.

43
00:01:57,970 --> 00:02:00,230
Now this allows us to shut everything down

44
00:02:00,230 --> 00:02:04,840
by pressing Ctrl+C, now it stopped that container,

45
00:02:04,840 --> 00:02:06,780
and now if we inspect all containers,

46
00:02:06,780 --> 00:02:08,703
we see that this container is stopped,

47
00:02:09,600 --> 00:02:13,000
But if we don't want to start in detached mode,

48
00:02:13,000 --> 00:02:15,593
we can also run docker-compose up -d,

49
00:02:16,900 --> 00:02:19,330
to start in detached mode.

50
00:02:19,330 --> 00:02:22,340
And if we do that, it will now start again,

51
00:02:22,340 --> 00:02:25,410
and then hand control back to us.

52
00:02:25,410 --> 00:02:27,960
And if we now want to stop all services

53
00:02:27,960 --> 00:02:30,560
and remove all containers and so on,

54
00:02:30,560 --> 00:02:33,880
we would run docker-compose down.

55
00:02:33,880 --> 00:02:36,530
And this deletes all containers,

56
00:02:36,530 --> 00:02:38,920
although the default network it created,

57
00:02:38,920 --> 00:02:41,330
and shuts everything down.

58
00:02:41,330 --> 00:02:44,480
It does not delete volumes though.

59
00:02:44,480 --> 00:02:46,080
If you want to do that,

60
00:02:46,080 --> 00:02:48,680
you need to add the -v flag here,

61
00:02:48,680 --> 00:02:52,163
then it also removes the data volume here.

62
00:02:53,970 --> 00:02:58,410
So with -v, you also remove volumes without -v,

63
00:02:58,410 --> 00:02:59,690
you don't do that.

64
00:02:59,690 --> 00:03:00,930
Which makes a lot of sense,

65
00:03:00,930 --> 00:03:04,830
because typically you want to persist data with volumes,

66
00:03:04,830 --> 00:03:06,960
So if volumes would be deleted,

67
00:03:06,960 --> 00:03:09,763
if you bring your services down, that would be bad.

68
00:03:10,920 --> 00:03:13,670
So long story short, docker compose-up,

69
00:03:13,670 --> 00:03:16,350
and docker-compose down are your friends,

70
00:03:16,350 --> 00:03:20,360
docker-compose up for building and pulling all the images,

71
00:03:20,360 --> 00:03:21,900
and then starting a container,

72
00:03:21,900 --> 00:03:24,580
and docker-compose down for stopping

73
00:03:24,580 --> 00:03:27,500
and removing all containers, and so on.

74
00:03:27,500 --> 00:03:30,653
This is how you use the docker-compose yaml file.

75
00:03:32,110 --> 00:03:35,700
And with that done, let's now move on to the back end.

76
00:03:35,700 --> 00:03:37,500
And let's see how we can actually

77
00:03:37,500 --> 00:03:39,580
move that to docker-compose.

78
00:03:39,580 --> 00:03:42,350
because at the moment, of course only the database,

79
00:03:42,350 --> 00:03:44,263
is running, and that's not enough.

