docker 几种磁盘卷挂载方式的区别

2017-03-15  本文已影响0人  eblly

[TOC]

容器与主机磁盘关联的方式主要有三种:

默认方式,不使用-v

使用docker run -d --name test01 erkules/galera,docker会在/var/lib/docker/volumes下随便命令一个目录与容器关联,并且使用docker rm -v会被删除。

-v /data

先查看/var/lib/docker/volumes下磁盘卷情况:

root@centos7 22:26:19 /var/lib/docker/volumes  $  ll
total 0
drwxr-xr-x. 3 root root 18 Jan 11 01:49 3f20fe8058ed83313defc4cf963fe452a0b371b8fcc88850373ff152b5f9f07c
drwxr-xr-x. 3 root root 18 Jan 12 23:28 b5defa5be7743001dac01a5a6e0caa02a123a0070b73aa1c013f219a8c8f9b19
drwxr-xr-x. 3 root root 18 Jan 12 23:28 c0ed357a27739077e719c67d05df7f0c3a84b769a9e2870ceefa99b593274e79
drwxr-xr-x. 3 root root 18 Jan 11 01:49 dfc0e08e2406b4648934d2bdcc93030fd2b2df17757bd668221b8b703559911d
drwxr-xr-x. 3 root root 18 Jan 11 01:49 f1ce00fb43b00d707e519b333ed0667613cfaf10143e0155d53cac79cfbfc15d
drwxr-xr-x. 3 root root 18 Jan 11 01:49 gitlab_data
drwxr-xr-x. 3 root root 18 Jan 11 02:38 jenkins_data
drwxr-xr-x. 3 root root 18 Jan 11 04:01 jenkins_data01
drwxr-xr-x. 3 root root 18 Jan 11 03:59 jenkins_data_20170110

使用命令docker run -d -v /var erkules/galera创建

root@centos7 22:31:05 /var/lib/docker/volumes  $  ll
total 0
drwxr-xr-x. 3 root root 18 Jan 11 01:49 3f20fe8058ed83313defc4cf963fe452a0b371b8fcc88850373ff152b5f9f07c
drwxr-xr-x. 3 root root 18 Jan 12 23:28 b5defa5be7743001dac01a5a6e0caa02a123a0070b73aa1c013f219a8c8f9b19
drwxr-xr-x. 3 root root 18 Jan 12 23:28 c0ed357a27739077e719c67d05df7f0c3a84b769a9e2870ceefa99b593274e79
drwxr-xr-x. 3 root root 18 Jan 11 01:49 dfc0e08e2406b4648934d2bdcc93030fd2b2df17757bd668221b8b703559911d
**drwxr-xr-x. 3 root root 18 Jan 14 22:30 e829ad258509455015d26bcd140779298153c8e8f998d72cda707e4f707f4332**
drwxr-xr-x. 3 root root 18 Jan 11 01:49 f1ce00fb43b00d707e519b333ed0667613cfaf10143e0155d53cac79cfbfc15d
drwxr-xr-x. 3 root root 18 Jan 11 01:49 gitlab_data
drwxr-xr-x. 3 root root 18 Jan 11 02:38 jenkins_data
drwxr-xr-x. 3 root root 18 Jan 11 04:01 jenkins_data01
drwxr-xr-x. 3 root root 18 Jan 11 03:59 jenkins_data_20170110

对比发现,新增了e829ad258509455015d26bcd140779298153c8e8f998d72cda707e4f707f4332目录。

root@centos7 22:26:20 /var/lib/docker/volumes  $  ll e829ad258509455015d26bcd140779298153c8e8f998d72cda707e4f707f4332/_data/
total 8
drwxr-xr-x.  2 root root    6 Apr 11  2014 backups
drwxr-xr-x.  5 root root   45 Mar  4  2016 cache
drwxr-xr-x. 27 root root 4096 Jan 14 22:30 lib
drwxrwsr-x.  2 root ftp     6 Apr 11  2014 local
lrwxrwxrwx.  1 root root    9 Mar  3  2016 lock -> /run/lock
drwxrwxr-x.  7 root  104 4096 Mar  4  2016 log
drwxrwsr-x.  2 root mem     6 Mar  3  2016 mail
drwxr-xr-x.  2 root root    6 Mar  3  2016 opt
lrwxrwxrwx.  1 root root    4 Mar  3  2016 run -> /run
drwxr-xr-x.  5 root root   57 Mar  3  2016 spool
drwxrwxrwt.  2 root root    6 Mar  3  2016 tmp

该目录存放的是新增容器/var目录。
使用docker rm -v 删除,对应的e829ad258509455015d26bcd140779298153c8e8f998d72cda707e4f707f4332也会被删除。

-v vol_name:/data

使用命令docker run -d --name test01 -v test_data:/data erkules/galera创建容器。

root@centos7 22:35:59 /var/lib/docker/volumes  $  ll
total 0
drwxr-xr-x. 3 root root 18 Jan 11 01:49 3f20fe8058ed83313defc4cf963fe452a0b371b8fcc88850373ff152b5f9f07c
drwxr-xr-x. 3 root root 18 Jan 12 23:28 b5defa5be7743001dac01a5a6e0caa02a123a0070b73aa1c013f219a8c8f9b19
drwxr-xr-x. 3 root root 18 Jan 12 23:28 c0ed357a27739077e719c67d05df7f0c3a84b769a9e2870ceefa99b593274e79
drwxr-xr-x. 3 root root 18 Jan 11 01:49 dfc0e08e2406b4648934d2bdcc93030fd2b2df17757bd668221b8b703559911d
drwxr-xr-x. 3 root root 18 Jan 11 01:49 f1ce00fb43b00d707e519b333ed0667613cfaf10143e0155d53cac79cfbfc15d
drwxr-xr-x. 3 root root 18 Jan 11 01:49 gitlab_data
drwxr-xr-x. 3 root root 18 Jan 11 02:38 jenkins_data
drwxr-xr-x. 3 root root 18 Jan 11 04:01 jenkins_data01
drwxr-xr-x. 3 root root 18 Jan 11 03:59 jenkins_data_20170110
**drwxr-xr-x. 3 root root 18 Jan 14 22:35 test_data**

新增test_data目录。
使用docker rm -v 删除,test_data目录仍然存在。

-v /home/data:/data

使用命令docker run -d --name test01 -v /home/test_data:/data erkules/galera创建容器,会在本机创建/home/test_data,并与容器/data关联。

使用docker rm -v删除,/home/test_data目录仍然存在。

上一篇下一篇

猜你喜欢

热点阅读