1
00:00:02,130 --> 00:00:05,220
So that were volumes and bind mounts.

2
00:00:05,220 --> 00:00:08,510
Here's a quick overview, since I know it's a lot to digest

3
00:00:08,510 --> 00:00:11,530
and easy to mix up these concepts.

4
00:00:11,530 --> 00:00:14,390
You basically have these three ways

5
00:00:14,390 --> 00:00:18,400
of using the dot v option when you use docker run.

6
00:00:18,400 --> 00:00:21,330
And, this first example would create

7
00:00:21,330 --> 00:00:24,690
an anonymous volume since you don't assign any name.

8
00:00:24,690 --> 00:00:27,490
The second example would create a named volume

9
00:00:27,490 --> 00:00:29,630
since you do assign a name.

10
00:00:29,630 --> 00:00:32,320
And in the third example, the name is actually

11
00:00:32,320 --> 00:00:36,350
an absolute path to a folder on your host machine

12
00:00:36,350 --> 00:00:39,140
and therefore this is then a bind mount.

13
00:00:39,140 --> 00:00:41,640
It's actually as easy as that.

14
00:00:41,640 --> 00:00:44,610
Now when it comes to the different features

15
00:00:44,610 --> 00:00:46,580
these different concepts have,

16
00:00:46,580 --> 00:00:48,890
I've got another comparison for you.

17
00:00:48,890 --> 00:00:51,960
With anonymous volumes, you create a volume

18
00:00:51,960 --> 00:00:54,540
which is kind of attached to a container.

19
00:00:54,540 --> 00:00:57,110
It's removed if the container is removed.

20
00:00:57,110 --> 00:01:00,140
It survives container shut down and restart,

21
00:01:00,140 --> 00:01:03,130
but if it's removed, it's gone and therefore

22
00:01:03,130 --> 00:01:05,290
if you use the dash dash rm

23
00:01:05,290 --> 00:01:06,910
when you ran the container,

24
00:01:06,910 --> 00:01:10,510
of course the volume is all gone when you stop the container

25
00:01:10,510 --> 00:01:13,300
because stopping then basically also means

26
00:01:13,300 --> 00:01:15,370
removing the container.

27
00:01:15,370 --> 00:01:17,740
Therefore, since it is removed when the container

28
00:01:17,740 --> 00:01:21,070
is removed, you can't use anonymous volumes

29
00:01:21,070 --> 00:01:23,920
to share data across containers.

30
00:01:23,920 --> 00:01:28,250
And you also can't use it to save data across container

31
00:01:28,250 --> 00:01:31,320
destruction and recreation as you saw.

32
00:01:31,320 --> 00:01:33,633
Anonymous volumes are not useful for that.

33
00:01:34,530 --> 00:01:37,390
But anonymous volumes either created

34
00:01:37,390 --> 00:01:40,522
with the volume instruction in the dockerfile

35
00:01:40,522 --> 00:01:44,000
or created with dash v, like this,

36
00:01:44,000 --> 00:01:48,890
can be useful for locking in certain data

37
00:01:48,890 --> 00:01:51,770
which already exists in the container.

38
00:01:51,770 --> 00:01:54,300
They can be useful for avoiding

39
00:01:54,300 --> 00:01:59,210
that this data then gets overwritten by another module.

40
00:01:59,210 --> 00:02:01,590
And that's something where anonymous volumes

41
00:02:01,590 --> 00:02:03,130
can save the day.

42
00:02:03,130 --> 00:02:08,090
In addition, anonymous volumes also still create

43
00:02:08,090 --> 00:02:12,130
a counterpart, a folder, on your host machine.

44
00:02:12,130 --> 00:02:14,780
Of course that's removed when the container's removed,

45
00:02:14,780 --> 00:02:18,050
but that exists as long as the container is running.

46
00:02:18,050 --> 00:02:20,220
And that of course means that docker

47
00:02:20,220 --> 00:02:22,550
doesn't have to store all the data inside

48
00:02:22,550 --> 00:02:24,200
of the container and doesn't have

49
00:02:24,200 --> 00:02:26,110
to manage all the data inside

50
00:02:26,110 --> 00:02:28,830
of this container read write layer.

51
00:02:28,830 --> 00:02:32,670
But that instead it can outsource certain data

52
00:02:32,670 --> 00:02:35,340
to your host machine file system.

53
00:02:35,340 --> 00:02:39,330
And this can also help with performance and efficiency.

54
00:02:39,330 --> 00:02:43,250
So that's why anonymous modules can be worth a closer look.

55
00:02:43,250 --> 00:02:45,000
And in this example,

56
00:02:45,000 --> 00:02:48,970
we could consider creating another anonymous volume,

57
00:02:48,970 --> 00:02:50,940
maybe inside of the docker file

58
00:02:50,940 --> 00:02:55,940
to mix things up for the temp folder.

59
00:02:56,570 --> 00:02:58,910
It's okay if we lose that folder

60
00:02:58,910 --> 00:03:00,740
when the container is removed,

61
00:03:00,740 --> 00:03:02,790
but for the reasons I just mentioned,

62
00:03:02,790 --> 00:03:06,280
for example for tiny performance improvements,

63
00:03:06,280 --> 00:03:09,580
it can be worth mapping this temp folder

64
00:03:09,580 --> 00:03:13,410
to an anonymous volume so the data managed in there

65
00:03:13,410 --> 00:03:16,790
is not managed in the docker container anymore,

66
00:03:16,790 --> 00:03:19,150
but actually well outsourced

67
00:03:19,150 --> 00:03:21,620
to the host file system, you could say.

68
00:03:21,620 --> 00:03:23,590
That could be useful and therefore

69
00:03:23,590 --> 00:03:26,083
it is something we can do here for sure.

70
00:03:27,300 --> 00:03:30,920
Obviously very useful, are named volumes.

71
00:03:30,920 --> 00:03:35,290
Named volumes can not be created in the dockerfile,

72
00:03:35,290 --> 00:03:38,660
but instead you create them with the dash v instruction

73
00:03:38,660 --> 00:03:40,400
when you run a container.

74
00:03:40,400 --> 00:03:43,080
They are named because you assign a name

75
00:03:43,080 --> 00:03:44,403
in front of the colon.

76
00:03:45,600 --> 00:03:47,700
Now the great thing about named volumes

77
00:03:47,700 --> 00:03:50,230
is that they're created in general.

78
00:03:50,230 --> 00:03:53,390
They're not tied to any specific container.

79
00:03:53,390 --> 00:03:55,860
They do survive container shut down

80
00:03:55,860 --> 00:03:58,740
and also the removal of containers.

81
00:03:58,740 --> 00:04:01,090
If you want to remove a named volume,

82
00:04:01,090 --> 00:04:03,580
you can still do that, but you have to do it

83
00:04:03,580 --> 00:04:07,100
with a separate command built into the Docker CLI.

84
00:04:07,100 --> 00:04:08,763
We'll have a look at that later.

85
00:04:10,200 --> 00:04:12,900
Now since they survived container removal,

86
00:04:12,900 --> 00:04:15,100
you can use named volumes

87
00:04:15,100 --> 00:04:18,230
to share data across multiple containers,

88
00:04:18,230 --> 00:04:20,269
Something we didn't do in this module,

89
00:04:20,269 --> 00:04:21,990
but of course you could do that.

90
00:04:21,990 --> 00:04:25,340
You could mount one of the same named module

91
00:04:25,340 --> 00:04:27,290
to multiple different containers,

92
00:04:27,290 --> 00:04:29,000
and hence the data in there

93
00:04:29,000 --> 00:04:31,340
could be shared between containers.

94
00:04:31,340 --> 00:04:33,160
And you can also use them

95
00:04:33,160 --> 00:04:37,790
to store data across container shutdowns and removals.

96
00:04:37,790 --> 00:04:40,173
That is what we did in this module.

97
00:04:41,320 --> 00:04:43,400
And then we had bind mounts.

98
00:04:43,400 --> 00:04:46,610
Bind mounts serve a different purpose.

99
00:04:46,610 --> 00:04:51,200
Here we know where data is stored on the host machine.

100
00:04:51,200 --> 00:04:55,040
Bind mounts are also not tied to one specific container.

101
00:04:55,040 --> 00:04:57,400
You can attach them to multiple containers

102
00:04:57,400 --> 00:05:01,350
and they do survive container shutdown and removal.

103
00:05:01,350 --> 00:05:04,830
If you want to clear the data of a bind mount,

104
00:05:04,830 --> 00:05:08,200
you actually have to delete it on your host machine.

105
00:05:08,200 --> 00:05:10,850
So here I would have to delete all the content here

106
00:05:10,850 --> 00:05:13,790
in my project to also remove it in the container.

107
00:05:13,790 --> 00:05:16,490
You can't delete it with a docker command.

108
00:05:16,490 --> 00:05:18,210
And that makes a lot of sense,

109
00:05:18,210 --> 00:05:21,470
because it is a folder on your system after all

110
00:05:21,470 --> 00:05:24,700
and you don't want to accidentally delete this somehow.

111
00:05:24,700 --> 00:05:27,260
Now of course you can share them across containers

112
00:05:27,260 --> 00:05:29,400
and you can also reuse them on one

113
00:05:29,400 --> 00:05:32,040
of the same container across restarts.

114
00:05:32,040 --> 00:05:33,593
This also works.

115
00:05:34,450 --> 00:05:37,363
And these are the three main ways we have

116
00:05:37,363 --> 00:05:40,490
for managing data inside of a container.

117
00:05:40,490 --> 00:05:43,670
I hope I could make it clear what the differences are

118
00:05:43,670 --> 00:05:45,510
and when you use which.

119
00:05:45,510 --> 00:05:47,253
And of course it should be needless to say

120
00:05:47,253 --> 00:05:48,800
that throughout this course,

121
00:05:48,800 --> 00:05:51,380
we'll also have plenty of other examples

122
00:05:51,380 --> 00:05:52,483
where it shows this.

