docker(三) 数据管理

数据卷

启动nginx容器,挂在到/data目录下

[root@test1 ~]# docker run -it --name volume-test1 -h nginx -v /data centos
[root@nginx /]# ls /data/

查看对应的系统目录

[root@test1 ~]# docker inspect volume-test1 | grep Source
"Source": "/var/lib/docker/volumes/4d1fece4eec5c31c9a10ac62542da22a85a026121f5d8a3f73c8e5ca62ba133c/_data",
[root@test1 ~]# cd /var/lib/docker/volumes/4d1fece4eec5c31c9a10ac62542da22a85a026121f5d8a3f73c8e5ca62ba133c/_data
[root@test1 _data]# touch hehe

容器内查看,生成hehe文件

[root@nginx /]# ls /data/

hehe

指定系统的目录位置opt/(系统路径):/opt(容器路径):ro(只读)

[root@test1 ~]# docker run -it --name volume-test2 -h nginx -v /opt:/opt centos
[root@nginx /]# ls /opt
hello rh

数据卷容器

把其他数据卷挂载过来

root@test1 ~]# docker run -it --name volume-test3 --volumes-from volume-test1 centos
[root@377fc168e866 /]# ls
anaconda-post.log bin data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@377fc168e866 /]# ls /data
hehe test
[root@377fc168e866 /]#

 

posted @ 2018-11-01 14:15  cornerxin  阅读(99)  评论(0)    收藏  举报