Docker的存储驱动

作者:亚搏app官网    发布时间:2019-11-09 02:10    浏览:109 次

[返回]

Docker存储驱动

1. Docker存款和储蓄驱动历史

Docker最近支撑的greph driver包蕴:

  • AUFS
  • device-mapper
  • btrfs
  • overlayfs(重点)

有关各存款和储蓄驱的亲力亲为介绍参照Docker各个存款和储蓄驱动原理及应用途景和特性测量检验对照

2. Docker overlayfs driver

1) 介绍

docker使用overlaysf的介绍如下:

  • lowerdir指向image layer;
  • upperdir指向container layer;
  • merged整合lowerdir与upperdir提统统一视图给容器作为根文件系统

如下图:
图片 1

2卡塔尔容器内文件的读写优先级情形

I. read file
  • upperdir存在,从container layer读取;
  • upperdir不存在,从lowerdir,即 image layer读取;
II. write file
  • upperdir存在,直接在upperdir写;
  • upperdir不存在,overlay发起copy_up操作,从lowerdir拷贝文件到upperdir实行写,拷贝只会在首先次展开时发生。
III. deleting files and directories
  • 去除文件时,upperdir会创制贰个witheout文件,会隐讳lowerdir的文件(非删除卡塔 尔(阿拉伯语:قطر‎;
  • 删除目录时,upperdir会创制三个opaque diectory,隐蔽lowerdir的目录;

3). overlayfs driver实践

  • 指定overlay driver启动:
$dockerd --storage-driver=overlay
$docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.06.0-ce
Storage Driver: overlay
 Backing Filesystem: extfs
 Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
  • 下载叁个镜像:
$docker pull centos:centos6
$docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              centos6             7ea307891843        4 weeks ago         194MB
  • 翻看镜像的呼应目录
$ls /var/lib/docker/overlay/
8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7
$ls /var/lib/docker/overlay/8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7/root/
bin  etc  home  lib  lib64  lost+found  media  mnt  opt  root  sbin  selinux  srv  tmp  usr  var
  • 创办容器
$docker run -it centos:centos6 /bin/bash
#在host里查看
$ls /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/
lower-id  merged/   upper/    work/
cat /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/lower-id
8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7
$cat /proc/mounts
overlay /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/merged overlay rw,relatime,lowerdir=/var/lib/docker/overlay/8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7/root,upperdir=/var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/upper,workdir=/var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/work 0 0

能够见见,容器对应的目录有两个(merged, upper, work卡塔尔国, work用于overlayfs完毕copy_up操作, lower-id保存images ID。

  • 容器内创造文件
$echo "hello" > /root/f1.txt
$ls /root/
anaconda-ks.cfg  f1.txt  install.log  install.log.syslog

Host上overlay目录变化

$ls /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/merged/root/
anaconda-ks.cfg  f1.txt  install.log  install.log.syslog
$ls /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/upper/root/
f1.txt
$ls /var/lib/docker/overlay/8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7/root/root/
anaconda-ks.cfg  install.log  install.log.syslog
  • 容器内去除文件
$rm /root/install.log
$ls /root/

Host上overlay目录变化

$ls /var/lib/docker/overlay/8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7/root/root/
anaconda-ks.cfg  install.log  install.log.syslog

$ls /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/merged/root/
anaconda-ks.cfg  f1.txt  install.log.syslog

$ls /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/upper/root/* -l
-rw-r--r-- 1 root root    6 Sep  3 22:17 /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/upper/root/f1.txt
#发现upperdir多了一下instll.log文件
c--------- 1 root root 0, 0 Sep  3 22:24 /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/upper/root/install.log

$cat /var/lib/docker/overlay/12e6cab3449f07e2eeb8441ec366c214a9550130ea1367bd5e58b6375b00d9e8/lower-id
8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7

$ls /var/lib/docker/overlay/8c2dc4e8a8bb0bca70b6304984089f9f6fcf6e093ce9cf9818af3316ad7fb0d7/root/root/
anaconda-ks.cfg  install.log  install.log.syslog

搜索