1
00:00:02,210 --> 00:00:05,200
So let's comment this MySQL container in.

2
00:00:05,200 --> 00:00:07,070
It shouldn't come as a surprise

3
00:00:07,070 --> 00:00:10,010
that we also have an official MySQL image

4
00:00:10,010 --> 00:00:11,050
which we can use.

5
00:00:11,050 --> 00:00:13,450
And we are going to use step two,

6
00:00:13,450 --> 00:00:15,090
well launch a database

7
00:00:15,090 --> 00:00:16,430
or launch a container

8
00:00:16,430 --> 00:00:18,710
that has a MySQL database in it.

9
00:00:18,710 --> 00:00:21,490
It's very comparable to the MongoDB image

10
00:00:21,490 --> 00:00:23,373
which we used earlier in the course.

11
00:00:24,330 --> 00:00:25,400
So here,

12
00:00:25,400 --> 00:00:27,770
I want to add an image

13
00:00:27,770 --> 00:00:29,270
and the image which I want to use here

14
00:00:29,270 --> 00:00:30,980
is MySQL image

15
00:00:30,980 --> 00:00:33,600
and here I want to use version 5.7

16
00:00:33,600 --> 00:00:35,883
so this tag of this image.

17
00:00:37,000 --> 00:00:38,520
This will pull in this image

18
00:00:38,520 --> 00:00:39,690
and inside of the image

19
00:00:39,690 --> 00:00:41,760
when it is started as a container,

20
00:00:41,760 --> 00:00:44,530
a MySQL database will be started.

21
00:00:44,530 --> 00:00:45,630
Now this database

22
00:00:45,630 --> 00:00:48,690
will later be accessed by our PHP code

23
00:00:48,690 --> 00:00:50,670
which will live in this PHP container

24
00:00:50,670 --> 00:00:52,170
or which will be handled

25
00:00:52,170 --> 00:00:53,620
by SP PHP container

26
00:00:53,620 --> 00:00:56,930
and since all these services are in the same network,

27
00:00:56,930 --> 00:00:58,880
we will be able to talk to this database

28
00:00:58,880 --> 00:01:00,090
without any issues

29
00:01:00,090 --> 00:01:02,460
simply by using this container name.

30
00:01:02,460 --> 00:01:04,120
So we don't need to configure anything

31
00:01:04,120 --> 00:01:06,220
regarding the networks here,

32
00:01:06,220 --> 00:01:07,380
but there is one other thing

33
00:01:07,380 --> 00:01:09,480
which we do need to configure here,

34
00:01:09,480 --> 00:01:11,930
and that is the environment.

35
00:01:11,930 --> 00:01:14,570
We need to provide some environment variables,

36
00:01:14,570 --> 00:01:16,800
which are used by this image,

37
00:01:16,800 --> 00:01:19,560
to setup a database,

38
00:01:19,560 --> 00:01:22,820
a user, a password and so on.

39
00:01:22,820 --> 00:01:25,450
And we find the detailed description again,

40
00:01:25,450 --> 00:01:27,000
on the Docker Hub page

41
00:01:27,000 --> 00:01:28,493
for this MySQL image.

42
00:01:29,470 --> 00:01:32,400
So here you can see which environment variables can be set,

43
00:01:32,400 --> 00:01:33,573
and what they do.

44
00:01:34,560 --> 00:01:37,610
Now there are a couple of variables I want to set here,

45
00:01:37,610 --> 00:01:41,530
however, I will set them not in this compose file

46
00:01:41,530 --> 00:01:43,560
but in the ".env file."

47
00:01:43,560 --> 00:01:45,730
So again I will edit "env folder"

48
00:01:45,730 --> 00:01:49,143
and in there myMySQL.env file.

49
00:01:50,160 --> 00:01:55,160
Now here I want to add the MYSQL _DATABASE variable,

50
00:01:55,740 --> 00:01:57,593
so this one here,

51
00:01:58,500 --> 00:02:01,440
and set this to an initial database name

52
00:02:01,440 --> 00:02:03,560
of a default initial database

53
00:02:03,560 --> 00:02:06,193
which will be created when this container starts up.

54
00:02:07,100 --> 00:02:09,169
Now I will set this to a homestead,

55
00:02:09,169 --> 00:02:11,763
you can find this in the Laravel documentation.

56
00:02:13,040 --> 00:02:16,160
I also will set a default user,

57
00:02:16,160 --> 00:02:18,150
again that's just another

58
00:02:18,150 --> 00:02:20,468
environment variable which we can use.

59
00:02:20,468 --> 00:02:23,470
And I'll set to that to a HOMESTEAD as well,

60
00:02:23,470 --> 00:02:26,450
again using some Laravel defaults here,

61
00:02:26,450 --> 00:02:28,770
then add a MySQL PASSWORD

62
00:02:28,770 --> 00:02:31,731
to add a password for this initial root user

63
00:02:31,731 --> 00:02:33,990
then I will set this to secrete.

64
00:02:33,990 --> 00:02:37,150
Add a MySQL ROOT PASSWORD

65
00:02:37,150 --> 00:02:39,490
and also set this to secrete,

66
00:02:39,490 --> 00:02:41,323
and yeah that should be it.

67
00:02:42,250 --> 00:02:44,850
With that we can go back to docker compose

68
00:02:44,850 --> 00:02:48,860
and add this env file option here,

69
00:02:48,860 --> 00:02:50,620
under MySQL container

70
00:02:50,620 --> 00:02:52,710
and then point at the env folder

71
00:02:52,710 --> 00:02:55,550
and there add the mysql.env file.

72
00:02:55,550 --> 00:02:57,950
To utilize the environment variables

73
00:02:57,950 --> 00:02:59,640
specified in that file

74
00:02:59,640 --> 00:03:00,773
in that container.

75
00:03:01,710 --> 00:03:05,980
And that is it for our free application containers.

76
00:03:05,980 --> 00:03:08,820
Now in order to test whether everything works,

77
00:03:08,820 --> 00:03:10,550
or if we made some mistake

78
00:03:10,550 --> 00:03:12,930
we need a Laravel application,

79
00:03:12,930 --> 00:03:15,010
and we will actually create that

80
00:03:15,010 --> 00:03:16,880
with this composer tool.

81
00:03:16,880 --> 00:03:19,503
So lets works on this composer container next.

