docker的数据卷管理
-
mkdir -p /data/volumes
-
挂载目录
|
1
2
3
|
[root@web01 ~]
# docker run -d --name nginx-volumes -v /data/volumes:/data nginx
1263f51d5bd1114c7f1582a0efb68266ce367629f01a64693cd15cf115165392
本地的
/data/volumes
挂载到容器的
/data
目录下
|
3.进入容器写文件测试
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@web01 ~]
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1263f51d5bd1 nginx
"nginx -g 'daemon off"
5 minutes ago Up 5 minutes 80
/tcp
, 443
/tcp
nginx-volumes
a04f5eee61b5 nginx
"nginx -g 'daemon off"
15 minutes ago Up 15 minutes 443
/tcp
, 59.110.25.215:89->80
/tcp
dokcer-volumes
1f3d2f356995 nginx
"nginx -g 'daemon off"
41 minutes ago Up 41 minutes 443
/tcp
, 59.110.25.215:88->80
/tcp
mynginx
[root@web01 ~]
# bash dockerin.sh 1f3d2f356995
root@1263f51d5bd1:/
# cd /data
root@1263f51d5bd1:
/data
# ls
root@1263f51d5bd1:
/data
# touch test01 test02
root@1263f51d5bd1:
/data
# ls
test01 test02
root@1263f51d5bd1:
/data
#
|
4.linux本机查看
|
1
2
3
4
5
6
7
|
[root@web01 volumes]
# ll
total 0
-rw-r--r-- 1 root root 0 Jan 3 22:16 test01
-rw-r--r-- 1 root root 0 Jan 3 22:16 test02
[root@web01 volumes]
# pwd
/data/volumes
[root@web01 volumes]
#
|
5.挂载多个目录
|
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
|
[root@web01 volumes]
# docker run -d --name nginx-volumes02 -v /data/volumes2:/data/volumes2 -v /data/volumes3:/data/volumes3 nginx
5b33955e8addab36c3c183a754d7f82e3ba6c94f1b865d1f4ef366af8ba9e67b
[root@web01 volumes]
#
[root@web01 ~]
# bash dockerin.sh 5b33955e8addab36c
root@5b33955e8add:/
# cd /data/
root@5b33955e8add:
/data
# ls
volumes2 volumes3
root@5b33955e8add:
/data
# touch volumes2/002
root@5b33955e8add:
/data
# touch volumes3/003
root@5b33955e8add:
/data
#
也是完全OK的
[root@web01 data]
# tree
.
├── volumes
│ ├── test01
│ └── test02
├── volumes2
│ └── 002
└── volumes3
└── 003
3 directories, 4 files
[root@web01 data]
#
|
6.docker的劵共享机制
|
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
|
[root@web01 data]
# docker run -d --name nginx-volumes-from --volumes-from nginx-volumes02 nginx
3342b2a88ba7121ec19e66fc388d8a19e5499e93fe786452bba295f66c9a1904
nginx-volumes02是一个容器,此容器挂载了两个目录
那么nginx-volumes-from将继承nginx-volumes02的目录,不管nginx-volumes02是否运行
[root@web01 ~]
# bash dockerin.sh 3342b2a88ba7121e
root@3342b2a88ba7:
/data
# cd volumes2
root@3342b2a88ba7:
/data/volumes2
# ls
002
root@3342b2a88ba7:
/data/volumes2
# touch 00vo
root@3342b2a88ba7:
/data/volumes2
# cd ../
root@3342b2a88ba7:
/data
# ls
volumes2 volumes3
root@3342b2a88ba7:
/data
# cd volumes3
root@3342b2a88ba7:
/data/volumes3
# ls
003
root@3342b2a88ba7:
/data/volumes3
# touch 003vo
root@3342b2a88ba7:
/data/volumes3
#
linux系统查看
[root@web01 data]
# tree
.
├── volumes
│ ├── test01
│ └── test02
├── volumes2
│ ├── 002
│ └── 00vo
└── volumes3
├── 003
└── 003vo
3 directories, 6 files
[root@web01 data]
#
|