# ls / bin boot dev etc home initrd.img initrd.img.old lib lib64 lost+found media mnt opt proc root run sbin snap srv sys tmp usr var vmlinuz vmlinuz.old
# chroot $HOME/test /bin/bash
bash-4.3# ls / bin lib lib64
rootfs - 容器镜像
挂载在容器根目录上,用来为容器进程提供隔离后执行环境的文件系统,即rootfs(容器镜像)
rootfs只是操作系统所包含的文件、配置和目录,并不包含操作系统的内核
在Linux中,这两部分是分开存放的,操作系统只有在开机启动时才会加载指定版本的内核镜像
同一台机器上的所有容器,都共享宿主机操作系统的内核
容器进程
启用Linux Namespace配置
设置指定的Cgroups参数
切换进程的根目录(Change Root)
系统调用优先级:pivot_root > chroot
Union File System
定义
功能:将多个不同位置的目录联合挂载到同一个目录下
1 2 3 4 5 6 7 8 9
# tree . ├── A │ ├── a │ └── x ├── B │ ├── b │ └── x └── C
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# mount -t aufs -o dirs=./A:./B none ./C
# tree . ├── A │ ├── a │ └── x ├── B │ ├── b │ └── x └── C ├── a ├── b └── x
# docker pull ubuntu Using default tag: latest latest: Pulling from library/ubuntu 345e3491a907: Pull complete 57671312ef6f: Pull complete 5e9250ddb7d0: Pull complete Digest: sha256:adf73ca014822ad8237623d388cedf4d5346aa72c270c5acc01431cc93e18e2d Status: Downloaded newer image for ubuntu:latest
镜像只读层
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# ll /var/lib/docker/aufs/diff total 20 drwx------ 5 root root 4096 Jun 7 16:48 ./ drwx------ 5 root root 4096 Jun 6 23:47 ../ drwxr-xr-x 3 root root 4096 Jun 7 16:48 08c5295ce91a073d1e6d7b6050a28e3f87132270114935d028f6534b5728370b/ drwxr-xr-x 17 root root 4096 Jun 7 16:48 5ca9eeca21a96f0cefff1648b23d9b98e31ed3ca2c2954807b4dcf6756242a17/ drwxr-xr-x 5 root root 4096 Jun 7 16:48 8ca42f2d821bdcdb493baa315e0fd8d39a8da7e26f1ad6ae4d1830c9657ad0b8/
# ll /var/lib/docker/aufs/mnt/ total 20 drwx------ 5 root root 4096 Jun 7 16:48 ./ drwx------ 5 root root 4096 Jun 6 23:47 ../ drwxr-xr-x 2 root root 4096 Jun 7 16:48 08c5295ce91a073d1e6d7b6050a28e3f87132270114935d028f6534b5728370b/ drwxr-xr-x 2 root root 4096 Jun 7 16:48 5ca9eeca21a96f0cefff1648b23d9b98e31ed3ca2c2954807b4dcf6756242a17/ drwxr-xr-x 2 root root 4096 Jun 7 16:48 8ca42f2d821bdcdb493baa315e0fd8d39a8da7e26f1ad6ae4d1830c9657ad0b8/
1 2 3 4 5 6 7 8
# ls /var/lib/docker/aufs/diff/08c5295ce91a073d1e6d7b6050a28e3f87132270114935d028f6534b5728370b/ run
# ls /var/lib/docker/aufs/diff/5ca9eeca21a96f0cefff1648b23d9b98e31ed3ca2c2954807b4dcf6756242a17/ bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var
# ls /var/lib/docker/aufs/diff/8ca42f2d821bdcdb493baa315e0fd8d39a8da7e26f1ad6ae4d1830c9657ad0b8/ etc usr var
# ls /var/lib/docker/aufs/diff/08c5295ce91a073d1e6d7b6050a28e3f87132270114935d028f6534b5728370b run
# ls /var/lib/docker/aufs/diff/8ca42f2d821bdcdb493baa315e0fd8d39a8da7e26f1ad6ae4d1830c9657ad0b8 etc usr var
# ls /var/lib/docker/aufs/diff/5ca9eeca21a96f0cefff1648b23d9b98e31ed3ca2c2954807b4dcf6756242a17 bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var