docker guest 是否将硬盘设备安装到文件而不是目录?

docker guest 是否将硬盘设备安装到文件而不是目录?

我已运行以下 docker 命令来创建 Ubuntu 映像的实例...

docker run -it ubuntu bash

当我发出安装命令时,我看到以下内容......

root@ca13e87462b5:/# mount
overlay on / type overlay (rw,relatime,lowerdir=/var/lib/docker/overlay2/l/O253SM3ZGX5EFP7OSBPPU5UW2C:/var/lib/docker/overlay2/l/IZEDWP7V4P4JWPLEL4EMN6GA5V:/var/lib/docker/overlay2/l/ZMFQPLBLMSGQYI7LDX5FSBHLEY:/var/lib/docker/overlay2/l/AVPGKJLG4AQJZLP3PKPGWQOMK6:/var/lib/docker/overlay2/l/6AFZ5ARHQ3PKYRWFQPUULZIMHB,upperdir=/var/lib/docker/overlay2/5a86c70a335f15d9c93bfb440b63b64aaef2b03b35ea42e3cef3609f96075514/diff,workdir=/var/lib/docker/overlay2/5a86c70a335f15d9c93bfb440b63b64aaef2b03b35ea42e3cef3609f96075514/work)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev type tmpfs (rw,nosuid,size=65536k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,relatime,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (ro,nosuid,nodev,noexec,relatime,xattr,name=systemd)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (ro,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (ro,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (ro,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/pids type cgroup (ro,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/rdma type cgroup (ro,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/blkio type cgroup (ro,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpuset type cgroup (ro,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/freezer type cgroup (ro,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/devices type cgroup (ro,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/memory type cgroup (ro,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (ro,nosuid,nodev,noexec,relatime,hugetlb)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
/dev/sdb2 on /etc/resolv.conf type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/sdb2 on /etc/hostname type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/sdb2 on /etc/hosts type ext4 (rw,relatime,errors=remount-ro,data=ordered)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k)
devpts on /dev/console type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
proc on /proc/bus type proc (ro,relatime)
proc on /proc/fs type proc (ro,relatime)
proc on /proc/irq type proc (ro,relatime)
proc on /proc/sys type proc (ro,relatime)
proc on /proc/sysrq-trigger type proc (ro,relatime)
tmpfs on /proc/asound type tmpfs (ro,relatime)
tmpfs on /proc/acpi type tmpfs (ro,relatime)
tmpfs on /proc/kcore type tmpfs (rw,nosuid,size=65536k,mode=755)
tmpfs on /proc/keys type tmpfs (rw,nosuid,size=65536k,mode=755)
tmpfs on /proc/timer_list type tmpfs (rw,nosuid,size=65536k,mode=755)
tmpfs on /proc/sched_debug type tmpfs (rw,nosuid,size=65536k,mode=755)
tmpfs on /proc/scsi type tmpfs (ro,relatime)
tmpfs on /sys/firmware type tmpfs (ro,relatime)

所以我发出了一个空闲磁盘命令......

root@ca13e87462b5:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay         219G  162G   46G  79% /
tmpfs            64M     0   64M   0% /dev
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sdb2       219G  162G   46G  79% /etc/hosts
shm              64M     0   64M   0% /dev/shm
tmpfs           7.9G     0  7.9G   0% /proc/asound
tmpfs           7.9G     0  7.9G   0% /proc/acpi
tmpfs           7.9G     0  7.9G   0% /proc/scsi
tmpfs           7.9G     0  7.9G   0% /sys/firmware

在我看来,设备 /dev/sdb2 的挂载点是一个文件 - /etc/hosts。

我不知道我可以将设备安装到文件中。我误解了这里发生了什么?

如果我在 /etc 上执行 ls ,我会看到主机是一个文件......

root@ca13e87462b5:/# ls -al /etc
total 268
drwxr-xr-x 1 root root    4096 Feb 24 17:40 .
drwxr-xr-x 1 root root    4096 Feb 24 17:40 ..
-rw------- 1 root root       0 Feb  4 21:03 .pwd.lock
-rw-r--r-- 1 root root    3028 Feb  4 21:03 adduser.conf
drwxr-xr-x 2 root root    4096 Feb  4 21:04 alternatives
drwxr-xr-x 1 root root    4096 Feb  4 21:03 apt
-rw-r--r-- 1 root root    2319 Apr  4  2018 bash.bashrc
-rw-r--r-- 1 root root     367 Jan 27  2016 bindresvport.blacklist
drwxr-xr-x 2 root root    4096 Feb  4 21:04 cron.daily
-rw-r--r-- 1 root root    2969 Feb 28  2018 debconf.conf
-rw-r--r-- 1 root root      11 Jun 25  2017 debian_version
drwxr-xr-x 2 root root    4096 Feb  4 21:04 default
-rw-r--r-- 1 root root     604 Aug 13  2017 deluser.conf
drwxr-xr-x 1 root root    4096 Feb  4 21:04 dpkg
-rw-r--r-- 1 root root      96 Feb  4 21:03 environment
-rw-r--r-- 1 root root      37 Feb  4 21:02 fstab
-rw-r--r-- 1 root root    2584 Feb  1  2018 gai.conf
-rw-r--r-- 1 root root     446 Feb  4 21:03 group
-rw-r----- 1 root shadow   374 Feb  4 21:03 gshadow
-rw-r--r-- 1 root root      92 Apr  9  2018 host.conf
-rw-r--r-- 1 root root      13 Feb 24 17:40 hostname
-rw-r--r-- 1 root root     174 Feb 24 17:40 hosts
drwxr-xr-x 2 root root    4096 Feb  4 21:04 init.d
-rw-r--r-- 1 root root      26 Aug 19  2018 issue
-rw-r--r-- 1 root root      19 Aug 19  2018 issue.net
drwxr-xr-x 3 root root    4096 Feb  4 21:03 kernel
-rw-r--r-- 1 root root    7274 Feb  4 21:04 ld.so.cache
-rw-r--r-- 1 root root      34 Jan 27  2016 ld.so.conf
drwxr-xr-x 2 root root    4096 Feb  4 21:04 ld.so.conf.d
-rw-r--r-- 1 root root     267 Apr  9  2018 legal
-rw-r--r-- 1 root root     191 Feb  7  2018 libaudit.conf
-rw-r--r-- 1 root root   10550 Jan 25  2018 login.defs
drwxr-xr-x 2 root root    4096 Feb  4 21:04 logrotate.d
-rw-r--r-- 1 root root     105 Aug 19  2018 lsb-release
-rw-r--r-- 1 root root       0 Feb  4 21:04 machine-id
-rw-r--r-- 1 root root     812 Mar 24  2018 mke2fs.conf
lrwxrwxrwx 1 root root      12 Feb 24 17:40 mtab -> /proc/mounts
-rw-r--r-- 1 root root      91 Apr  9  2018 networks
-rw-r--r-- 1 root root     497 Oct  5  2016 nsswitch.conf
drwxr-xr-x 2 root root    4096 Feb  4 21:02 opt
lrwxrwxrwx 1 root root      21 Aug 19  2018 os-release -> ../usr/lib/os-release
-rw-r--r-- 1 root root     552 Apr  4  2018 pam.conf
drwxr-xr-x 2 root root    4096 Feb  4 21:04 pam.d
-rw-r--r-- 1 root root     926 Feb  4 21:03 passwd
-rw-r--r-- 1 root root     581 Apr  9  2018 profile
drwxr-xr-x 2 root root    4096 Feb  4 21:04 profile.d
drwxr-xr-x 2 root root    4096 Oct 25  2017 rc0.d
drwxr-xr-x 2 root root    4096 Oct 25  2017 rc1.d
drwxr-xr-x 2 root root    4096 Oct 25  2017 rc2.d
drwxr-xr-x 2 root root    4096 Oct 25  2017 rc3.d
drwxr-xr-x 2 root root    4096 Oct 25  2017 rc4.d
drwxr-xr-x 2 root root    4096 Oct 25  2017 rc5.d
drwxr-xr-x 2 root root    4096 Oct 25  2017 rc6.d
drwxr-xr-x 2 root root    4096 Feb  4 21:03 rcS.d
-rw-r--r-- 1 root root     628 Feb 24 17:40 resolv.conf
-rwxr-xr-x 1 root root     268 Jul 21  2017 rmt
-rw-r--r-- 1 root root    4141 Jan 25  2018 securetty
drwxr-xr-x 4 root root    4096 Feb  4 21:03 security
drwxr-xr-x 2 root root    4096 Feb  4 21:04 selinux
-rw-r----- 1 root shadow   501 Feb  4 21:03 shadow
-rw-r--r-- 1 root root      73 Feb  4 21:03 shells
drwxr-xr-x 2 root root    4096 Feb  4 21:03 skel
-rw-r--r-- 1 root root       0 Feb  4 21:03 subgid
-rw-r--r-- 1 root root       0 Feb  4 21:03 subuid
-rw-r--r-- 1 root root    2683 Jan 17  2018 sysctl.conf
drwxr-xr-x 2 root root    4096 Feb  4 21:04 sysctl.d
drwxr-xr-x 3 root root    4096 Oct 25  2017 systemd
drwxr-xr-x 2 root root    4096 Feb  4 21:04 terminfo
drwxr-xr-x 2 root root    4096 Feb  4 21:04 update-motd.d

答案1

不。Docker 是在文件上绑定安装文件。

man 8 mount

绑定坐骑

在其他地方重新安装部分文件层次结构。通话内容是:

  mount --bind olddir newdir

...

还可以重新挂载单个文件(在单个文件上)

Docker 看起来像是在文件上挂载设备的原因是该mount -l命令的输出不完整:它没有显示绑定挂载的源路径。

再次来自man 8 mount

列出坐骑

保留列表模式只是为了向后兼容。

要获得更强大和可定制的输出,请使用 findmnt(8)

运行findmnt,您将看到绑定安装的源(以 的形式device[source-path])。

相关内容