1、Doker支持的文件系统
2、Aufs文件系统介绍
Aufs 文件系统实验
Ubuntu下使用的是AUFS文件系统
通过docker info查看Docker信息:
root@compute2:/var/lib/docker/aufs/mnt# docker info
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 7
Server Version: 1.12.0
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 39
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge null host overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-34-generic
Operating System: Ubuntu 16.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 32
Total Memory: 125.7 GiB
Name: compute2
ID: KGBV:CXG7:2AD4:CXTH:RGTI:5SIT:VWLS:GAGN:Y6ZG:LYFR:DH4N:MYEY
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
127.0.0.0/8
root@compute2:/var/lib/docker/aufs/mnt#
Docker存储目录
root@compute2:/var/lib/docker/aufs# pwd
/var/lib/docker/aufs/
Docker镜像存储目录
root@compute2:/var/lib/docker/aufs/diff# pwd
/var/lib/docker/aufs/diff
root@compute2:/var/lib/docker/aufs/diff# ls -lahs| xargs ls
root@compute2:/var/lib/docker/aufs/mnt# pwd
/var/lib/docker/aufs/mnt
Aufs实验:测试将两个目录挂载到同一个目录下
root@compute2:~# mkdir dir1
root@compute2:~# mkdir dir2
root@compute2:~# mkdir aufs
root@compute2:~# mount -t aufs -o br=/root/dir1=ro:/root/dir2=rw none /root/aufs
root@compute2:~# cd aufs/
root@compute2:~/aufs# ls
file1.txt file2.txt
root@compute2:~/aufs# echo wirte >> file1.txt
-bash: file1.txt: Read-only file system
root@compute2:~/aufs# echo wirte >> file2.txt
root@compute2:~/aufs# cat file2.txt
file2
wirte
root@compute2:~/aufs#
3、Devicemapper文件系统介绍
Devicemapper文件系统实验:
先修改配置文件修改使用的文件系统为devicemapper文件 系统
root@compute2:~# vim /etc/default/docker
DOCKER_OPTS="--storage-driver=devicemapper"
Centos7下 默认使用的是devicemapper
[root@compute default]# docker info
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 1
Server Version: 1.10.3
Storage Driver: devicemapper
Pool Name: docker-253:1-41956292-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 425.4 MB
Data Space Total: 107.4 GB
Data Space Available: 29.9 GB
Metadata Space Used: 1.18 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.146 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2016-06-09)
Execution Driver: native-0.2
Logging Driver: journald
Plugins:
Volume: local
Network: null host bridge
Kernel Version: 3.10.0-327.22.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 2
CPUs: 2
Total Memory: 3.702 GiB
Name: compute.novalocal
ID: VN7J:AB7A:YIO4:QXQN:6KRO:SSBY:A7RF:IFZJ:JHQA:4N6S:FGLS:PIXO
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Registries: docker.io (secure)
[root@compute default]# cd /var/lib/docker/devicemapper/devicemapper/
[root@compute devicemapper]# ls
data metadata
Devicemapper文件系统使用测试
查看data文件的大小
[root@compute devicemapper]# ls -lahs
total 403M
0 drwx------. 2 root root 32 Sep 8 00:26 .
0 drwx------. 5 root root 50 Sep 8 00:29 ..
402M -rw-------. 1 root root 100G Sep 8 02:47 data
1.3M -rw-------. 1 root root 2.0G Sep 8 20:50 metadata
进入 容器创建一个200M的文件
[root@compute devicemapper]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6eb042a5a721 docker.io/cmer81/centos7-openstack "sh" 18 hours ago Up 18 hours docker-openstack
[root@compute devicemapper]# docker exec -it docker-openstack /bin/bash
[root@6eb042a5a721 /]# dd if=/dev/zero of=aa.txt bs=2M count=100
100+0 records in
100+0 records out
209715200 bytes (210 MB) copied, 0.214644 s, 977 MB/s
[root@6eb042a5a721 /]# ls -alhs
total 201M
4.0K drwxr-xr-x. 17 root root 4.0K Sep 8 20:57 .
4.0K drwxr-xr-x. 17 root root 4.0K Sep 8 20:57 ..
0 -rwxr-xr-x. 1 root root 0 Sep 8 02:45 .dockerenv
0 -rwxr-xr-x. 1 root root 0 Sep 8 02:45 .dockerinit
200M -rw-r--r--. 1 root root 200M Sep 8 20:57 aa.txt
再次查看data文件的大小
[root@compute ~]# cd /var/lib/docker/devicemapper/devicemapper/
[root@compute devicemapper]# ls -lahs
total 603M
0 drwx------. 2 root root 32 Sep 8 00:26 .
0 drwx------. 5 root root 50 Sep 8 00:29 ..
602M -rw-------. 1 root root 100G Sep 8 20:59 data
1.3M -rw-------. 1 root root 2.0G Sep 8 20:57 metadata
4、Overlayfs文件系统
修改docker 的主配置文件
root@compute2:~# vim /etc/default/docker
DOCKER_OPTS="--storage-driver=overlay"
root@compute2:~# service docker restart
root@compute2:~# grep overlayfs /proc/filesystems
root@compute2:~# modinfo overlayfs
filename: /lib/modules/4.4.0-34-generic/kernel/fs/overlayfs/overlay.ko
alias: overlayfs
alias: fs-overlayfs
alias: fs-overlay
license: GPL
description: Overlay filesystem
author: Miklos Szeredi <miklos@szeredi.hu>
srcversion: 0B3D6723476322D2ADDC9B2
depends:
intree: Y
vermagic: 4.4.0-34-generic SMP mod_unload modversions
root@compute2:~# mount -t overlay overlay -o lowerdir=/root/lower,upperdir=/root/upper /root/marged
5、volume
创建容器docker-volume1,并将容器中目录/root下映射到/data/volume下
root@compute2:/data/volume# docker run -d --name docker-volume1 -v /data/volume:/root cmer81/centos7-openstack
ede0cd25a6808c0cb044bca969cbd1285dc49c485ea2e71c1ffec1116ecb6b5a
root@compute2:/data/volume# docker exec -it docker-volume1 sh
sh-4.2# ls
anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run run.sh sbin srv sys tmp usr var
sh-4.2# cd root/
sh-4.2# ls
sh-4.2# touch test
sh-4.2# exit
exit
root@compute2:/data/volume# ls
test
--volumes-from参数实验:
可以实现容器间的数据共享,将上面创建的docker-volume1下映射到主机/data/volume共享到新建容器docker-volumes-from的/root中
root@compute2:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ede0cd25a680 cmer81/centos7-openstack "/run.sh" 15 minutes ago Up 15 minutes docker-volume1
47d5fe8a136a cmer81/centos7-openstack "/run.sh" 21 minutes ago Up 21 minutes docker-volume
root@compute2:~# docker run -it --name docker-volumes-from --volumes-from docker-volume1 cmer81/centos7-openstack sh
sh-4.2# ls
anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run run.sh sbin srv sys tmp usr var
sh-4.2# ls root
test
sh-4.2# exit
exit
root@compute2:~# cd /data/volume/
root@compute2:/data/volume# ls
test
root@compute2:/data/volume#
root@compute2:/data/volume# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
51617b348155 cmer81/centos7-openstack "sh" 5 minutes ago Up 2 seconds docker-volumes-from
ede0cd25a680 cmer81/centos7-openstack "/run.sh" 22 minutes ago Up 22 minutes docker-volume1
47d5fe8a136a cmer81/centos7-openstack "/run.sh" 27 minutes ago Up 27 minutes docker-volume
本文出自 “技术成就梦想” 博客,请务必保留此出处http://andyliu.blog.51cto.com/518879/1852670
原文地址:http://andyliu.blog.51cto.com/518879/1852670