[root@localhost volumes]# cd /tmp [root@localhost tmp]# mkdir overlay [root@localhost tmp]# cd overlay/ [root@localhost overlay]# mkdir low upper work merged low 最底层 upper 上一层 work 工作缓存 merged 用户的展现层或者叫挂载层。
[root@localhost overlay]# mount -t overlay overlay -olowerdir=./low,upperdir=./upper,workdir=./work ./merged [root@localhost overlay]# mount |tail -1 overlay on /tmp/overlay/merged type overlay (rw,relatime,seclabel,lowerdir=./low,upperdir=./upper,workdir=./work)
挂载成功。
[root@localhost overlay]# cd low [root@localhost low]# vi 1.txt 111111111111111112322 [root@localhost low]# cd ../upper/ [root@localhost upper]# vi 2.txt lkdfjsdfklsdjfslkdfjsdlkf [root@localhost upper]# yum -y install tree
[root@localhost upper]# cd .. [root@localhost overlay]# tree . ├── low │ └── 1.txt ├── merged │ ├── 1.txt │ └── 2.txt ├── upper │ └── 2.txt └── work └── work 5 directories, 4 files
low 最底层镜像层, upper容器运行的空白层, merged用户的挂载层。
[root@localhost overlay]# cd merged/ [root@localhost merged]# ls 1.txt 2.txt [root@localhost merged]# cat 1.txt 2.txt 111111111111111112322 lkdfjsdfklsdjfslkdfjsdlkf内容是一模一样的
修改1.txt
[root@localhost merged]# echo "this is a merged" >> 1.txt [root@localhost merged]# cd .. [root@localhost overlay]# tree . ├── low │ └── 1.txt ├── merged │ ├── 1.txt │ └── 2.txt ├── upper │ ├── 1.txt │ └── 2.txt └── work └── work 5 directories, 5 files
[root@localhost overlay]# cat upper/1.txt 111111111111111112322 this is a merged [root@localhost overlay]# cat low/1.txt low/ [root@localhost overlay]# cat low/1.txt 111111111111111112322 在最底层并未修改
[root@localhost overlay]# cd merged/ [root@localhost merged]# rm -rf 1.txt [root@localhost merged]# cd .. [root@localhost overlay]# tree . ├── low │ └── 1.txt ├── merged │ └── 2.txt ├── upper │ ├── 1.txt │ └── 2.txt └── work └── work 5 directories, 4 files
1.txt还在,但是一个特殊的文件类型
[root@localhost overlay]# cd upper/ [root@localhost upper]# ls -l 总用量 4 c---------. 1 root root 0, 0 12月 30 13:52 1.txt -rw-r--r--. 1 root root 26 12月 30 13:47 2.txt
1.txt代表文件已删除
[root@localhost upper]# cd ../merged/ [root@localhost merged]# ls 2.txt 如何还原。又回来了。 [root@localhost merged]# cd ../upper/ [root@localhost upper]# ls 1.txt 2.txt [root@localhost upper]# rm -rf 1.txt [root@localhost upper]# ls 2.txt [root@localhost upper]# cd ../merged/ [root@localhost merged]# ls 1.txt 2.txt [root@localhost upper]# cd .. [root@localhost overlay]# tree . ├── low │ └── 1.txt ├── merged │ ├── 1.txt │ └── 2.txt ├── upper │ └── 2.txt └── work └── work 5 directories, 4 files