1
00:00:02,120 --> 00:00:03,400
In docker compose,

2
00:00:03,400 --> 00:00:06,470
let's continue with the artisan container.

3
00:00:06,470 --> 00:00:09,960
We need the artisan tool to run certain level commands.

4
00:00:09,960 --> 00:00:12,090
For example, to populate the database

5
00:00:12,090 --> 00:00:13,463
with some initial data.

6
00:00:14,490 --> 00:00:18,350
Now, the artisan command, again, needs a custom docker file.

7
00:00:18,350 --> 00:00:21,830
However, I will simply use the PHP docker file here

8
00:00:21,830 --> 00:00:25,920
because I just need the same setup as we have it in here.

9
00:00:25,920 --> 00:00:28,610
So we can add the build configuration here

10
00:00:28,610 --> 00:00:32,070
or simply copy the one from the PHP container

11
00:00:32,070 --> 00:00:34,630
and add it here for artisan.

12
00:00:34,630 --> 00:00:37,570
Because it needs PHP to execute code.

13
00:00:37,570 --> 00:00:40,840
Artisan is a level command built with PHP.

14
00:00:40,840 --> 00:00:43,400
So it needs PHP to do that.

15
00:00:43,400 --> 00:00:45,820
Now, in addition, it needs volumes

16
00:00:45,820 --> 00:00:49,130
and there specifically it again, needs our source code.

17
00:00:49,130 --> 00:00:52,230
Because it is executed on our source code.

18
00:00:52,230 --> 00:00:56,160
We do things with our source code with that command.

19
00:00:56,160 --> 00:01:00,140
So we expose the source directory on our local host machine

20
00:01:00,140 --> 00:01:04,900
queue to good old /var/www/html folder

21
00:01:04,900 --> 00:01:07,840
inside of this container,

22
00:01:07,840 --> 00:01:10,583
because that's where our application will reside.

23
00:01:11,450 --> 00:01:13,670
And now I'll show you something interesting

24
00:01:13,670 --> 00:01:15,670
which I haven't shown you before.

25
00:01:15,670 --> 00:01:19,920
You can actually also set certain settings

26
00:01:19,920 --> 00:01:22,320
which you set in a docker file normally,

27
00:01:22,320 --> 00:01:24,320
inside of a docker-compose file

28
00:01:24,320 --> 00:01:26,970
to essentially override the settings

29
00:01:26,970 --> 00:01:28,670
inside of the docker file.

30
00:01:28,670 --> 00:01:32,700
And here I'm using the PHP docker file because I want PHP.

31
00:01:32,700 --> 00:01:35,540
I'm also happy with this working directory

32
00:01:35,540 --> 00:01:38,570
but I also want to add an entry point.

33
00:01:38,570 --> 00:01:42,260
And in the PHP image, we don't have an entry point.

34
00:01:42,260 --> 00:01:45,760
Simply because this PHP container, is in the end used

35
00:01:45,760 --> 00:01:49,380
by nginx to funnel individual files through it.

36
00:01:49,380 --> 00:01:51,430
So it's used like a utility container

37
00:01:51,430 --> 00:01:53,440
for nginx you could say.

38
00:01:53,440 --> 00:01:57,200
This is all good, but now I need to run my own command.

39
00:01:57,200 --> 00:02:00,240
And I wanna specify this as an entry point.

40
00:02:00,240 --> 00:02:02,800
We could create a separate docker file,

41
00:02:02,800 --> 00:02:07,090
but we can also simply add the entry point option here

42
00:02:07,090 --> 00:02:08,600
in docker compose.

43
00:02:08,600 --> 00:02:10,410
And this allows us to override

44
00:02:10,410 --> 00:02:12,350
or add if it doesn't exist yet

45
00:02:12,350 --> 00:02:15,140
the entry point in a docker file.

46
00:02:15,140 --> 00:02:16,834
So here we then specify it just

47
00:02:16,834 --> 00:02:19,600
as we would to do it inside of the docker file.

48
00:02:19,600 --> 00:02:22,157
And here I want to execute PHP.

49
00:02:23,340 --> 00:02:26,080
So this tool the executable,

50
00:02:26,080 --> 00:02:29,490
which is set up by this PHP base image.

51
00:02:29,490 --> 00:02:32,680
And I wanna execute a certain file with PHP.

52
00:02:32,680 --> 00:02:34,300
And that file can be found

53
00:02:34,300 --> 00:02:38,497
in the /var/www/html artisan folder.

54
00:02:39,440 --> 00:02:41,780
Or to be precise in the HTML folder

55
00:02:41,780 --> 00:02:43,860
and then it's the artisan file.

56
00:02:43,860 --> 00:02:47,090
And we can see this file in the source folder.

57
00:02:47,090 --> 00:02:48,920
It's this file here.

58
00:02:48,920 --> 00:02:51,650
This is a PHP file, but when you execute it

59
00:02:51,650 --> 00:02:55,300
it runs a utility program, which can do a lot of stuff.

60
00:02:55,300 --> 00:02:57,830
It's part of the level framework.

61
00:02:57,830 --> 00:03:01,470
And we're executing this file inside of the container

62
00:03:01,470 --> 00:03:04,280
with help of PHP and this PHP image.

63
00:03:04,280 --> 00:03:06,880
And we're adding this entry point to the image

64
00:03:06,880 --> 00:03:09,930
since it doesn't exist in our docker file.

65
00:03:09,930 --> 00:03:12,320
And we also don't want to add it here

66
00:03:12,320 --> 00:03:14,830
because we use this PHP docker file

67
00:03:14,830 --> 00:03:16,550
all to folder PHP container.

68
00:03:16,550 --> 00:03:19,323
And here, we don't want the entry point.

69
00:03:20,170 --> 00:03:23,680
So this is the setup we need for artisan here.

70
00:03:23,680 --> 00:03:27,160
Now with that, we already finished this container

71
00:03:27,160 --> 00:03:29,370
and let's also finish NPM now.

72
00:03:29,370 --> 00:03:34,300
NPM is quite simple, here I'll use the node image

73
00:03:34,300 --> 00:03:36,790
and there let's say node 14.

74
00:03:36,790 --> 00:03:39,370
And now we could either write a docker file

75
00:03:39,370 --> 00:03:42,480
to set the working directory and the entry point

76
00:03:42,480 --> 00:03:45,670
or we use our newly gained knowledge that we can add

77
00:03:45,670 --> 00:03:48,710
or override certain things here in docker compose.

78
00:03:48,710 --> 00:03:50,630
And we can utilize this to set

79
00:03:50,630 --> 00:03:54,100
the working directory here as well in docker compose.

80
00:03:54,100 --> 00:03:55,420
And that's what I mentioned earlier.

81
00:03:55,420 --> 00:03:57,050
You can do this here as well.

82
00:03:57,050 --> 00:04:01,030
I prefer docker files, but to show both I'll now do it here.

83
00:04:01,030 --> 00:04:05,050
And I'll set the working directory to /var/www/html

84
00:04:05,050 --> 00:04:08,130
as so often and enter entry point,

85
00:04:08,130 --> 00:04:10,090
which in this case is NPM.

86
00:04:10,090 --> 00:04:12,440
So that we expose this NPM command

87
00:04:12,440 --> 00:04:15,410
from inside our image, based on this node image

88
00:04:15,410 --> 00:04:17,510
so that we can use this NPM container

89
00:04:17,510 --> 00:04:19,803
to run NPM commands, inside of it.

90
00:04:20,829 --> 00:04:25,200
And now, I just also want to add a volume here.

91
00:04:25,200 --> 00:04:28,090
Because, I again, want to of course do all of that

92
00:04:28,090 --> 00:04:31,530
on my source code folder, and therefore bind that

93
00:04:31,530 --> 00:04:36,530
to the /var/www/html folder inside of the container.

94
00:04:36,830 --> 00:04:38,963
Same logic as for artisan.

95
00:04:40,130 --> 00:04:42,880
And now with that, we're done.

96
00:04:42,880 --> 00:04:44,700
Now, make sure that you got

97
00:04:44,700 --> 00:04:47,950
your application servers up and running.

98
00:04:47,950 --> 00:04:50,480
And let's now try the artisan command.

99
00:04:50,480 --> 00:04:52,780
And for this, we can use docker-compose run

100
00:04:52,780 --> 00:04:55,823
and then run the artisan container.

101
00:04:57,070 --> 00:04:59,740
Which internally then runs this artisan file

102
00:04:59,740 --> 00:05:00,573
with PHP

103
00:05:01,897 --> 00:05:03,720
at --rm though.

104
00:05:03,720 --> 00:05:06,000
So that it's removed and we're done.

105
00:05:06,000 --> 00:05:08,720
And now run the migrate command.

106
00:05:08,720 --> 00:05:11,900
Which is one of the artisan command's level supports.

107
00:05:11,900 --> 00:05:14,400
This will write some data to the database

108
00:05:14,400 --> 00:05:16,120
and it will therefore also check

109
00:05:16,120 --> 00:05:18,810
whether this database set up works.

110
00:05:18,810 --> 00:05:21,590
So let's hit enter, and this looks good.

111
00:05:21,590 --> 00:05:25,020
It's migrating and it migrated successfully.

112
00:05:25,020 --> 00:05:26,210
And this wouldn't work

113
00:05:26,210 --> 00:05:29,040
if we wouldn't have a database connection.

114
00:05:29,040 --> 00:05:31,740
So, with that, we also tested this.

115
00:05:31,740 --> 00:05:34,740
We're not going to test NPM here, but it should work.

116
00:05:34,740 --> 00:05:37,640
And we now have a nice setup here

117
00:05:37,640 --> 00:05:40,380
for a level PHP application.

118
00:05:40,380 --> 00:05:43,520
Yes, this definitely is a more complex setup

119
00:05:43,520 --> 00:05:45,830
but that's also the idea behind the course.

120
00:05:45,830 --> 00:05:49,440
Learn the basics and then also see more complex things

121
00:05:49,440 --> 00:05:50,673
being built with that.

122
00:05:51,610 --> 00:05:54,080
Now, when you build something like this on your own,

123
00:05:54,080 --> 00:05:55,350
it's totally normal

124
00:05:55,350 --> 00:05:57,650
that you build something like that step by step

125
00:05:57,650 --> 00:06:00,400
by googling, finding other solutions,

126
00:06:00,400 --> 00:06:01,890
taking courses like this

127
00:06:01,890 --> 00:06:04,350
and eventually you'll get to the point

128
00:06:04,350 --> 00:06:07,490
where you can build something like this totally on your own.

129
00:06:07,490 --> 00:06:10,660
Obviously, it also helps if you know level and PHP

130
00:06:10,660 --> 00:06:13,130
because you then know the building blocks you'll need

131
00:06:13,130 --> 00:06:14,380
like composer.

132
00:06:14,380 --> 00:06:17,500
If you don't know that, you obviously also have no chance

133
00:06:17,500 --> 00:06:19,290
of knowing that you need to add it.

134
00:06:19,290 --> 00:06:20,960
So don't be discouraged by that

135
00:06:20,960 --> 00:06:22,823
if you don't know PHP or level.

