1
00:00:02,220 --> 00:00:05,160
So by now we talked about volumes a lot.

2
00:00:05,160 --> 00:00:07,210
I hope it's clear why we use them

3
00:00:07,210 --> 00:00:09,530
and when you use which volume type

4
00:00:09,530 --> 00:00:11,810
or when you use a bind mount.

5
00:00:11,810 --> 00:00:15,510
Now I did say that volumes are managed by Docker.

6
00:00:15,510 --> 00:00:17,010
And this is true.

7
00:00:17,010 --> 00:00:19,540
When we run our container, as we did before,

8
00:00:19,540 --> 00:00:22,280
with all these dash V flags here,

9
00:00:22,280 --> 00:00:25,880
Docker we'll actually go ahead and create that volume,

10
00:00:25,880 --> 00:00:28,130
which also means that it creates a folder

11
00:00:28,130 --> 00:00:31,250
somewhere on the host machine automatically.

12
00:00:31,250 --> 00:00:34,793
It does this without us giving any extra instructions.

13
00:00:35,840 --> 00:00:38,560
Nonetheless, you can take a look under the hood

14
00:00:38,560 --> 00:00:41,350
and see what Docker actually did.

15
00:00:41,350 --> 00:00:44,160
Now here, I have my containers still up and running,

16
00:00:44,160 --> 00:00:47,350
and now if I type docker volume dash dash help,

17
00:00:47,350 --> 00:00:50,170
we'll see a couple of commands we can use

18
00:00:50,170 --> 00:00:52,700
together with docker volume, to have a look

19
00:00:52,700 --> 00:00:57,210
at all the volumes Docker's managing for all our containers.

20
00:00:57,210 --> 00:00:59,060
In this case, we have only one container

21
00:00:59,060 --> 00:01:01,050
but of course we could have multiple containers

22
00:01:01,050 --> 00:01:05,129
and then we could view all the volumes by all containers.

23
00:01:05,129 --> 00:01:07,240
So here we got various commands.

24
00:01:07,240 --> 00:01:09,940
And right now the LS command is interesting.

25
00:01:09,940 --> 00:01:13,890
It lists all the currently active volumes.

26
00:01:13,890 --> 00:01:17,840
And if I run this, we see that we got free volumes here.

27
00:01:17,840 --> 00:01:20,540
Two anonymous volumes, which you can tell

28
00:01:20,540 --> 00:01:24,733
by this super long cryptic name and one named volume.

29
00:01:25,960 --> 00:01:27,290
And that makes a lot of sense

30
00:01:27,290 --> 00:01:30,300
if we have a look at our docker run instruction.

31
00:01:30,300 --> 00:01:34,250
There, we have one named volume,

32
00:01:34,250 --> 00:01:35,950
this one here.

33
00:01:35,950 --> 00:01:39,300
And we did assign a name of feedback,

34
00:01:39,300 --> 00:01:41,540
which is why we see this name here.

35
00:01:41,540 --> 00:01:45,270
And then we have the anonymous volume for app node modules

36
00:01:45,270 --> 00:01:48,060
and the anonymous volume for app temp.

37
00:01:48,060 --> 00:01:50,570
So two anonymous volumes.

38
00:01:50,570 --> 00:01:53,270
The bind mount does not show up in this list

39
00:01:53,270 --> 00:01:56,890
because the bind mount is not a volume managed by Docker.

40
00:01:56,890 --> 00:02:01,120
As I said and mentioned earlier, this binds a local folder

41
00:02:01,120 --> 00:02:04,320
which we know, to a folder inside of the container.

42
00:02:04,320 --> 00:02:07,250
And of course therefore Docker does not manage this.

43
00:02:07,250 --> 00:02:10,169
It's our known folder on our host machine,

44
00:02:10,169 --> 00:02:13,060
Docker is not in control over that.

45
00:02:13,060 --> 00:02:15,790
But the other volumes are managed by Docker

46
00:02:15,790 --> 00:02:18,340
And managed by Docker also means

47
00:02:18,340 --> 00:02:21,000
that Docker will create this volume

48
00:02:21,000 --> 00:02:24,990
if it doesn't exist yet, when you run a container.

49
00:02:24,990 --> 00:02:29,380
You actually can also use docker volume create

50
00:02:29,380 --> 00:02:31,323
to create a volume on your own.

51
00:02:32,270 --> 00:02:35,660
If we enter dash help here, we see that we can specify

52
00:02:35,660 --> 00:02:37,220
a couple of options here

53
00:02:37,220 --> 00:02:38,720
though we don't have that many

54
00:02:38,720 --> 00:02:41,760
and these are advanced options, which we can ignore here

55
00:02:41,760 --> 00:02:43,890
and then your volume.

56
00:02:43,890 --> 00:02:47,830
So you can, for example, use docker volume create

57
00:02:48,810 --> 00:02:53,373
to create a volume named feedback files.

58
00:02:54,250 --> 00:02:57,660
And if you do that and you then run docker volume LS

59
00:02:57,660 --> 00:03:00,620
thereafter, you see that volume as well.

60
00:03:00,620 --> 00:03:02,720
And if you would now run your container

61
00:03:02,720 --> 00:03:06,850
you could also use this new feedback dash files volume here

62
00:03:06,850 --> 00:03:10,800
as a name for the named volume, instead of feedback.

63
00:03:10,800 --> 00:03:13,440
Now, if you don't create the volume in advance,

64
00:03:13,440 --> 00:03:15,310
Docker will create it for you,

65
00:03:15,310 --> 00:03:17,150
but you can also create it manually

66
00:03:17,150 --> 00:03:18,780
if you would like to do that.

67
00:03:18,780 --> 00:03:21,830
Often, of course, you'll leave it up to Dockerfile

68
00:03:21,830 --> 00:03:24,080
because since it creates automatically

69
00:03:24,080 --> 00:03:26,970
if you don't have a strong reason for doing it manually,

70
00:03:26,970 --> 00:03:28,220
why would you do it?

71
00:03:28,220 --> 00:03:30,960
Nonetheless, it is worth knowing that you can control this

72
00:03:30,960 --> 00:03:33,620
with the docker volume command.

73
00:03:33,620 --> 00:03:36,120
Now with this command, you can actually do more.

74
00:03:36,120 --> 00:03:38,220
You can also remove a volume

75
00:03:38,220 --> 00:03:41,620
or remove all unused local volumes

76
00:03:41,620 --> 00:03:43,623
and you can also inspect the volume.

77
00:03:44,560 --> 00:03:46,460
Now let's inspect first.

78
00:03:46,460 --> 00:03:48,890
So first of all, I'll list my volumes.

79
00:03:48,890 --> 00:03:51,320
And then I'll take this feedback volume here

80
00:03:51,320 --> 00:03:54,060
and run docker volume inspect feedback

81
00:03:54,060 --> 00:03:56,240
to look into this volume.

82
00:03:56,240 --> 00:04:00,360
And now we see some information about this volume here.

83
00:04:00,360 --> 00:04:04,700
We see when it was created, we see which drivers used

84
00:04:04,700 --> 00:04:06,340
which we can ignore here.

85
00:04:06,340 --> 00:04:10,070
And we see its name, possible options that are set up,

86
00:04:10,070 --> 00:04:11,600
nothing fancy here.

87
00:04:11,600 --> 00:04:13,750
And then also the mountpoint.

88
00:04:13,750 --> 00:04:16,970
And that's actually the path on our host machine

89
00:04:16,970 --> 00:04:18,450
where this is stored.

90
00:04:18,450 --> 00:04:21,839
I mentioned that Docker creates this automatically for us.

91
00:04:21,839 --> 00:04:24,023
Well, here is where it created this.

92
00:04:24,870 --> 00:04:26,810
Nonetheless, this is not a path

93
00:04:26,810 --> 00:04:29,020
you will find on your system because

94
00:04:29,020 --> 00:04:32,740
this is actually inside of a little virtual machine

95
00:04:32,740 --> 00:04:36,270
Docker set up on your system, so to say.

96
00:04:36,270 --> 00:04:38,200
If there is a basic virtual machine

97
00:04:38,200 --> 00:04:40,150
in which Docker runs, you could say

98
00:04:40,150 --> 00:04:42,340
and this is the path in that machine.

99
00:04:42,340 --> 00:04:45,030
It's not an actual path in your file system

100
00:04:45,030 --> 00:04:46,400
on your host machine.

101
00:04:46,400 --> 00:04:49,890
There, this virtual machine is then again mapped differently

102
00:04:49,890 --> 00:04:51,270
and that's what I meant with,

103
00:04:51,270 --> 00:04:54,930
it's hard to find out where this is actually stored.

104
00:04:54,930 --> 00:04:57,390
Therefore, of course, if you just inspect a volume

105
00:04:57,390 --> 00:04:58,930
to find out where it's stored,

106
00:04:58,930 --> 00:05:00,910
you're not going to be too happy.

107
00:05:00,910 --> 00:05:03,900
But if you, for example, wanna see if it's read only

108
00:05:03,900 --> 00:05:07,220
then you could inspect this because you would see this here

109
00:05:07,220 --> 00:05:10,320
under options, if it would be a read only volume.

110
00:05:10,320 --> 00:05:11,910
Which this one of course isn't

111
00:05:11,910 --> 00:05:14,853
which is why we don't see anything related to that here.

112
00:05:16,140 --> 00:05:18,940
Now, I said we can also remove volumes.

113
00:05:18,940 --> 00:05:23,730
And for example, we can remove the feedback files volume

114
00:05:23,730 --> 00:05:25,700
I created a couple of seconds ago

115
00:05:25,700 --> 00:05:29,970
with docker volume RM, and then the volume name.

116
00:05:29,970 --> 00:05:32,420
If I try to remove feedback though

117
00:05:32,420 --> 00:05:36,110
I get an error because this volume is currently in use.

118
00:05:36,110 --> 00:05:39,393
Of course, we got an active container based on that volume.

119
00:05:40,290 --> 00:05:44,950
So we should first stop feedback dash app, this container

120
00:05:44,950 --> 00:05:48,840
and there after, we will be able to remove this volume.

121
00:05:48,840 --> 00:05:51,730
Though of course you should keep in mind that with that

122
00:05:51,730 --> 00:05:54,560
we're going to remove all these text files

123
00:05:54,560 --> 00:05:56,370
that were created with our app.

124
00:05:56,370 --> 00:06:00,090
So we're removing all that data which we wanted to save

125
00:06:00,090 --> 00:06:02,010
across container restarts.

126
00:06:02,010 --> 00:06:04,120
So that is something you should be aware of.

127
00:06:04,120 --> 00:06:08,150
When you remove a volume, all the data in it is lost.

128
00:06:08,150 --> 00:06:10,560
And if you then create the same volume again,

129
00:06:10,560 --> 00:06:12,300
so a volume with the same name,

130
00:06:12,300 --> 00:06:15,800
that will not bring back your data of course.

131
00:06:15,800 --> 00:06:17,430
Still I'm going to do it here

132
00:06:17,430 --> 00:06:19,100
so did I can show this to you,

133
00:06:19,100 --> 00:06:23,210
but now if I restart my container

134
00:06:23,210 --> 00:06:26,180
with this docker run command, you will note

135
00:06:26,180 --> 00:06:31,103
that if I go there and I try to view feedback.awesome.txt

136
00:06:32,030 --> 00:06:34,540
we fail to get to this file because

137
00:06:34,540 --> 00:06:36,663
I removed the volume in the mean time.

138
00:06:37,820 --> 00:06:40,810
Now we can also use docker volume prune

139
00:06:40,810 --> 00:06:43,200
to remove all unused volumes

140
00:06:43,200 --> 00:06:44,950
in case you had multiple volumes

141
00:06:44,950 --> 00:06:46,730
you wanna get rid off.

142
00:06:46,730 --> 00:06:50,850
Now, I'll again stop my feedback app container here.

143
00:06:50,850 --> 00:06:54,060
And then I'm going to list all my volumes again.

144
00:06:54,060 --> 00:06:56,580
And we only see the newly created feedback app

145
00:06:56,580 --> 00:06:59,450
which was created because I restarted the container

146
00:06:59,450 --> 00:07:01,143
after I last deleted it.

147
00:07:02,000 --> 00:07:03,450
What you also see is

148
00:07:03,450 --> 00:07:06,210
that the anonymous volumes are missing here

149
00:07:06,210 --> 00:07:08,250
because as I explained earlier

150
00:07:08,250 --> 00:07:11,130
anonymous volumes are automatically removed

151
00:07:11,130 --> 00:07:14,280
if the container for which they were created is removed.

152
00:07:14,280 --> 00:07:16,750
And this container is removed when it's stopped

153
00:07:16,750 --> 00:07:19,023
because of dash dash RM option.

154
00:07:20,130 --> 00:07:23,610
Well, and that finally is it about volumes

155
00:07:23,610 --> 00:07:26,780
and what you should know about volumes up to this point.

156
00:07:26,780 --> 00:07:29,300
I know it's a lot, the most important thing

157
00:07:29,300 --> 00:07:30,460
is that you remember

158
00:07:30,460 --> 00:07:32,730
how they work and why you use them.

159
00:07:32,730 --> 00:07:36,540
And that you will remember how they can override each other

160
00:07:36,540 --> 00:07:37,413
so to say.

