forked from nramnad/java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvolume.txt
More file actions
228 lines (134 loc) · 6.87 KB
/
volume.txt
File metadata and controls
228 lines (134 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Docker Volume
*************
Data available even though container got deleted
Why do we need to have docker volume?
Data no longer available once container is stopped or removed
Docker container did not persist data permanently
Different types of Volume Mounts
Volume Mount and Bind Mount
***************************
Containers are usually immutable and ephemeral
Immuntable Infra: Only re-deploy container and never change
This is the ideal scenario: What about DB or configuration related info
Docker gives us features to ensure these "seperation of concerns"
This is called "Persistent Data"
Volume Mount
************
Volumes are created at Host File system and managed by Docker
Make special location outside of the container
At RHEL Linux or Ubuntu, volumes are located at /var/lib/docker/volumes/
Volumes can be created by two way
1) docker volume create
2) Run time
Volume can be mounted to multiple containers
Volume can not be removed
Volume can be removed by docker volume prune command
Usage of the Volumes
********************
1) Sharing data among various containers
2) When you want to backup, restore, or migrate data amoung multiple hosts
Bind Mount
**********
Directory can be available anywhere in the Docker host system
Link container path to host path
(Maps a host file or directory to a container file or directory)
- Changes can be incorporated at host files and container files
- There is a sync between host and container and vice versa
*******************************************************************************************************
Lab
***
Listing Docker volume
******************
docker volume ls
Creating a Volume
*****************
docker volume create --name customerdb
docker volume ls
Use Case 1: Creating a container with volume and remove the container once you exit from the container
******************************************************************************************
docker run -it --name suse1 --rm -v customerdb:/platniumcustomer centos
- suse1 : Name of the container
- -v: Volume
- Platniumcustomer : Creating a folder at Container OS
- --rm indicating that once you exit from container and automatically remove the container
Output is
You are getting into container OS and apply ls -la command
You get one folder of "platniumcustomer"
Apply command for Mount
df -h
which list out all mount details and you can get platniumcustomer
Get into platniumcustomer folder and add few files under this folder
After created files, apply below
exit
You are now Base os and exit from container os
Since, you apply --rm commands container get deleted automatically
You can get to know after apply below
docker ps
and
docker ps -a
docker volume inspect customerdb
You can get output of Json format and refer Mount Point Path
Go to Mount Point path where you get the file which you created inside the container
Lesson Learned: Even if you deleted container, data can be alive at base machine
******************************************************************************************************
Use Case 2: Creating a new container with same volume
*************************************************
docker run -it --name suse2 --rm -v customerdb:/platniumcustomer1 centos
Created automatically folder of platniumcustomer1 and file which you created earlier container
of suse1
Old container deleted, but container data stored in the Host machine volume
Host machine volume bind with new container of suse2
CREATING A VOLUME THAT PERSISTS WHEN THE CONTAINER GOT DELETED
*******************************************************************************************************
Use Case 3: Creating a volume dynamically (During run time)
*******************************************************
docker run -it --name suse3 -v customerdb1:/regularcustomer centos
You are now at container os of centos
Go to regularcustomer folder and create a new file
After created the file, apply CTRL pq from the container
(Now whatever data I captured here that persists to host machine too and if I remove the container,
the same data persists to host machine)
Now container alive now since we did not use --rm command
*******************************************************************************************************
Use Case 4: Container Data Persists after stop the container
********************************************************
Data can be alive, after stop the container
Apply
docker stop <container name or id>
Data can be persits, even after stop the container
docker start <container name or id>
Get into container OS as per below
container exec -it < Container id> bash
Get into container os and you go respective foler where you can get respective files
******************************************************************************************************
Use Case 5: Creating Volume from an existing directory with data
***************************************************************
docker run -it --rm --name suse4 -v customerdb2:/var centos
Get into container os and system created var directory automatically
exit from container os
*******************************************************************************************************
Use Case 6: Linking data with other container
*********************************************
docker run -it --rm --name suse5 -v customerdb2:/linkcustomer centos ls linkcustomer
Above command is for displaying ls commnad, that is going to display contents of the volume
without get into bash termainals
*******************************************************************************************************
Use Case 7: Data sharing between containers
*******************************************
docker run -it --name suse6 -v customerdb3:/sharecustomer centos
You are now at container os and get into sharecustomer folder
At sharecustomer folder, you create a few files and save it
Exit from container os
Use Case 8 : Create suse7 container and mount volumes from suse6
****************************************************************
docker run -it --name suse7 --volumes-from suse6 centos
Get into sharecustomer folder where you get the data
******************************************************************************************************
Use Case 9: Bind Volume
***********************
docker run -it --name suse8 -v /hostvolume/iosmobile:/containervolume/iosmobile centos
Now, you are in the container
Get into containervolume/iosmobile directory and create few files
After exit from the container, at host system you can get data which created at container
At host system, edit the files (Whatever you edited which can be available at container too)
You log into container and go to respective file and check it