docker 存储

 

[root@docker01 ~]# docker run --name b1 -v /data -it busybox
/ # ls
bin   data  dev   etc   home  proc  root  sys   tmp   usr   var
/ # ls /data/
[root@docker01 ~]# docker inspect b1

"Mounts": [
{
"Type": "volume",
"Name": "8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05",
"Source": "/var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data",  ###宿主机卷目录
"Destination": "/data",   ###容器卷目录
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],

"Volumes": {
                "/data": {}
            },
我们在宿主机的目录/var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data创建一个文件:

[root@docker01 ~]# cd /var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data
[root@docker01 _data]# pwd
/var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data
[root@docker01 _data]# echo "hello container" >> test.html
[root@docker01 _data]# ll
total 4
-rw-r--r-- 1 root root 16 Mar 28 04:23 test.html

[root@docker01 ~]# docker run --name b1 -v /data -it busybox
/ # ls
bin data dev etc home proc root sys tmp usr var
/ # ls /data/
/ # ls /data/
test.html
/ # cat /data/test.html     ####此时容器上也有此文件
hello container

####另外一种方式

[root@docker01 ~]# docker run --name b1 --rm -v /data/volumes/b1:/data -it busybox
/ # 



[root@docker01 ~]# docker inspect b1

"Mounts": [
{
"Type": "bind",
"Source": "/data/volumes/b1",
"Destination": "/data",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],

######inspect 格式输出#####

[root@docker01 ~]# docker inspect -f {{.NetworkSettings.Networks.bridge.Gateway}} b1
172.17.0.1
[root@docker01 ~]# docker inspect -f {{.NetworkSettings.Networks.bridge.MacAddress}} b1
02:42:ac:11:00:02
[root@docker01 ~]# 

######两个容器可共享一个存储卷#######

 

 

posted @ 2019-03-29 14:46  大漠之烟  阅读(174)  评论(0编辑  收藏  举报