查看一下宿主机的分区挂载情况

[root@localhost ~]# df
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  52403200 26388668  26014532  51% /
devtmpfs                  1923288        0   1923288   0% /dev
tmpfs                     1933472        0   1933472   0% /dev/shm
tmpfs                     1933472    17200   1916272   1% /run
tmpfs                     1933472        0   1933472   0% /sys/fs/cgroup
/dev/mapper/centos-home  47760604    32928  47727676   1% /home
/dev/sda1                  508588   155828    352760  31% /boot
tmpfs                      386696        0    386696   0% /run/user/0

同时运行两个个容器,一个基于busybox镜像,一个基于ubuntu镜像

[root@localhost /]# docker run -it busybox /bin/sh
[root@localhost ~]# docker run -it ubuntu /bin/bash

可以看到两个个运行的容器:

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
29f3173876a6        busybox             "/bin/sh"           20 seconds ago      Up 18 seconds                           agitated_jones
720a3161bf18        ubuntu              "/bin/bash"         3 minutes ago       Up 3 minutes                            wizardly_khorana

再次查看分区挂载情况:

[root@localhost ~]# df
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  52403200 26388668  26014532  51% /
devtmpfs                  1923288        0   1923288   0% /dev
tmpfs                     1933472        0   1933472   0% /dev/shm
tmpfs                     1933472    17200   1916272   1% /run
tmpfs                     1933472        0   1933472   0% /sys/fs/cgroup
/dev/mapper/centos-home  47760604    32928  47727676   1% /home
/dev/sda1                  508588   155828    352760  31% /boot
tmpfs                      386696        0    386696   0% /run/user/0
/dev/dm-4                10474496    34660  10439836   1% /var/lib/docker/devicemapper/mnt/2b35dda0f86ac7d4700621892343a498ea9ff8eb2ca9bcc2599456de997258a3
shm                         65536        0     65536   0% /var/lib/docker/containers/a18d392e6d01cb7ab9dfcf728a1cd50fd1b4db087a9c3b3373db7f37d594f35a/shm
/dev/dm-5                10474496   141224  10333272   2% /var/lib/docker/devicemapper/mnt/5ea73d5812e830cf15918fecec87e4119ade209c7af9342dca60f86d67d3ab4f
shm                         65536        0     65536   0% /var/lib/docker/containers/720a3161bf18a175136a25c065b97f045e481dd5ee46d4288ea08a58e4205f3d/shm

可以看到后面多出了四个分区,/dev/dm-4/dev/dm-5分别对应两个容器的文件系统,使用tree命令查看两个挂载点的目录结构:

[root@localhost ~]# tree -L 2 /var/lib/docker/devicemapper/mnt/5ea73d5812e830cf15918fecec87e4119ade209c7af9342dca60f86d67d3ab4f
/var/lib/docker/devicemapper/mnt/5ea73d5812e830cf15918fecec87e4119ade209c7af9342dca60f86d67d3ab4f
├── id
└── rootfs
    ├── bin
    ├── boot
    ├── dev
    ├── etc
    ├── home
    ├── lib
    ├── lib64
    ├── media
    ├── mnt
    ├── opt
    ├── proc
    ├── root
    ├── run
    ├── sbin
    ├── srv
    ├── sys
    ├── tmp
    ├── usr
    └── var

20 directories, 1 file
[root@localhost ~]# tree -L 2 /var/lib/docker/devicemapper/mnt/2b35dda0f86ac7d4700621892343a498ea9ff8eb2ca9bcc2599456de997258a3
/var/lib/docker/devicemapper/mnt/2b35dda0f86ac7d4700621892343a498ea9ff8eb2ca9bcc2599456de997258a3
    ├── id
    └── rootfs
        ├── bin
        ├── dev
        ├── etc
        ├── home
        ├── proc
        ├── root
        ├── sys
        ├── tmp
        ├── usr
        └── var

    11 directories, 1 file

可以看出,两个目录中存放的是两个容器对应的文件系统根节点。

这时候,再运行一个容器基于镜像busybox,再次查看分区:

[root@localhost ~]# df
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  52403200 26388668  26014532  51% /
devtmpfs                  1923288        0   1923288   0% /dev
tmpfs                     1933472        0   1933472   0% /dev/shm
tmpfs                     1933472    17200   1916272   1% /run
tmpfs                     1933472        0   1933472   0% /sys/fs/cgroup
/dev/mapper/centos-home  47760604    32928  47727676   1% /home
/dev/sda1                  508588   155828    352760  31% /boot
tmpfs                      386696        0    386696   0% /run/user/0
/dev/dm-4                10474496    34660  10439836   1% /var/lib/docker/devicemapper/mnt/2b35dda0f86ac7d4700621892343a498ea9ff8eb2ca9bcc2599456de997258a3
shm                         65536        0     65536   0% /var/lib/docker/containers/a18d392e6d01cb7ab9dfcf728a1cd50fd1b4db087a9c3b3373db7f37d594f35a/shm
/dev/dm-5                10474496   141224  10333272   2% /var/lib/docker/devicemapper/mnt/5ea73d5812e830cf15918fecec87e4119ade209c7af9342dca60f86d67d3ab4f
shm                         65536        0     65536   0% /var/lib/docker/containers/720a3161bf18a175136a25c065b97f045e481dd5ee46d4288ea08a58e4205f3d/shm
/dev/dm-6                10474496    34660  10439836   1% /var/lib/docker/devicemapper/mnt/e5cb5359515b967a6af0a8e115ed343b8bc8c3df3f22645e0d3c8bd9de81851c
shm                         65536        0     65536   0% /var/lib/docker/containers/29f3173876a6660ae495d15a28094e60f6a96106be483a4ad4ed39c4af29044b/shm

可以看到,又生成了两个分区,可见,每次启动一个容器,都会对应生成一个分区,并挂载到对应的容器id命名的目录中去,这个目录里面rootfs就是容器中对应的系统的根挂载点。

[root@localhost ~]# tree -L 2 /var/lib/docker/devicemapper/mnt/e5cb5359515b967a6af0a8e115ed343b8bc8c3df3f22645e0d3c8bd9de81851c
/var/lib/docker/devicemapper/mnt/e5cb5359515b967a6af0a8e115ed343b8bc8c3df3f22645e0d3c8bd9de81851c
├── id
└── rootfs
    ├── bin
    ├── dev
    ├── etc
    ├── home
    ├── mnt
    ├── proc
    ├── root
    ├── sys
    ├── tmp
    ├── usr
    └── var

12 directories, 1 file
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐