1
00:00:02,240 --> 00:00:04,030
Now we know the problem.

2
00:00:04,030 --> 00:00:05,740
What's the solution?

3
00:00:05,740 --> 00:00:09,170
Docker has a built in feature called volumes.

4
00:00:09,170 --> 00:00:12,320
And volumes help us with persisting data,

5
00:00:12,320 --> 00:00:16,940
and solving the problem I outlined in the last lecture.

6
00:00:16,940 --> 00:00:21,170
Now how do we utilize volumes in our application?

7
00:00:21,170 --> 00:00:24,830
In this Docker application, for example.

8
00:00:24,830 --> 00:00:28,410
First of all, we have to understand what exactly volumes are

9
00:00:28,410 --> 00:00:30,250
and how they work.

10
00:00:30,250 --> 00:00:34,310
Volumes are folders on your host machine,

11
00:00:34,310 --> 00:00:35,740
so not in the container,

12
00:00:35,740 --> 00:00:36,880
not in the image,

13
00:00:36,880 --> 00:00:39,620
but on your host machine hard drive,

14
00:00:39,620 --> 00:00:41,150
which are mounted,

15
00:00:41,150 --> 00:00:44,670
which basically means, made available or mapped,

16
00:00:44,670 --> 00:00:47,080
into containers.

17
00:00:47,080 --> 00:00:51,840
So volumes are folders on your host machine,

18
00:00:51,840 --> 00:00:53,530
on your computer,

19
00:00:53,530 --> 00:00:56,430
which you make Docker aware of

20
00:00:56,430 --> 00:00:57,920
and which are then mapped

21
00:00:57,920 --> 00:01:02,180
to folders inside of a Docker container.

22
00:01:02,180 --> 00:01:05,340
Now that might sound a bit like the COPY instruction

23
00:01:05,340 --> 00:01:06,770
from the Docker file.

24
00:01:06,770 --> 00:01:09,400
But keep in mind that this instruction,

25
00:01:09,400 --> 00:01:13,700
really just takes a snapshot of the path and files

26
00:01:13,700 --> 00:01:15,483
you would tell it to copy,

27
00:01:15,483 --> 00:01:19,420
and then it copies these files and folders into the image,

28
00:01:19,420 --> 00:01:20,440
and that's it.

29
00:01:20,440 --> 00:01:23,730
There's no on-going relation or connection,

30
00:01:23,730 --> 00:01:26,060
it's just a one time snapshot,

31
00:01:26,060 --> 00:01:28,860
which is copied into the image.

32
00:01:28,860 --> 00:01:31,130
With volumes that's different.

33
00:01:31,130 --> 00:01:33,730
Here you can really connect a folder,

34
00:01:33,730 --> 00:01:35,180
inside of the container,

35
00:01:35,180 --> 00:01:39,610
to a folder outside of the container, on your host machine.

36
00:01:39,610 --> 00:01:42,610
And changes in either folder,

37
00:01:42,610 --> 00:01:44,830
will be reflected in the other one.

38
00:01:44,830 --> 00:01:47,700
So if you add a file on your host machine,

39
00:01:47,700 --> 00:01:49,907
it is accessible inside of the container,

40
00:01:49,907 --> 00:01:54,100
and if the container adds a file in that mapped path,

41
00:01:54,100 --> 00:01:56,130
it is available outside of the container,

42
00:01:56,130 --> 00:01:57,823
in the host machine as well.

43
00:01:58,740 --> 00:02:02,140
And therefore, because of this mechanism,

44
00:02:02,140 --> 00:02:05,270
volumes allow you to persist data.

45
00:02:05,270 --> 00:02:08,090
Volumes persist and continue to exist

46
00:02:08,090 --> 00:02:10,430
even if a container is shut down.

47
00:02:10,430 --> 00:02:11,750
That's important.

48
00:02:11,750 --> 00:02:14,630
If you add a volume to a container,

49
00:02:14,630 --> 00:02:17,830
the volume will not be removed,

50
00:02:17,830 --> 00:02:20,010
when a container is removed,

51
00:02:20,010 --> 00:02:21,370
it survives,

52
00:02:21,370 --> 00:02:24,483
and therefore the data, in a volume survives.

53
00:02:25,340 --> 00:02:26,930
And containers can both

54
00:02:26,930 --> 00:02:31,140
read and write data from and to a volume.

55
00:02:31,140 --> 00:02:33,580
And that's of course a powerful feature.

56
00:02:33,580 --> 00:02:37,020
Which we can use for folders,

57
00:02:37,020 --> 00:02:40,620
which we want to access from outside our container,

58
00:02:40,620 --> 00:02:43,490
and/or simply for data

59
00:02:43,490 --> 00:02:46,230
that should survive container shutdown

60
00:02:46,230 --> 00:02:48,950
and the removal of a container.

61
00:02:48,950 --> 00:02:52,170
Because if the data is also saved outside of the container,

62
00:02:52,170 --> 00:02:55,513
of course it survives the removal of the container.

