为什么我没有对在 docker 中作为 tmpfs 挂载的 /run 的 rw 访问权限?

问题描述

❯ docker run -d -it --name debian --mount type=tmpfs,destination=/run,tmpfs-mode=1777 --mount type=tmpfs,destination=/tmp,tmpfs-mode=1777 debian bash


❯ docker exec -it debian ls -lrtd /run /tmp
  drwxrwxrwt 2 root root 40 Jul 27 14:06 /tmp
  drwxr-xr-x 2 root root 40 Jul 27 14:06 /run

这里,为什么 tmpfs-mode=1777 没有单独应用于 /run?
它适用于其他目录。
这里有什么具体原因吗?

解决方法

我相信由于 /run 已经存在,该目录的权限正在应用于 tmpfs 挂载。 /tmp 也发生了同样的事情,但由于底层 /tmp 目录的权限已经与您想要的相匹配,因此您不会注意到。

您可以通过在其他目录(例如,tmpfs)上创建 /root 挂载来验证这一点。你会看到他们采用了挂载点的权限。

如果您确实需要对 /run 的权限有所不同,您可以在 /run 上构建具有所需权限的新映像(或者在容器运行后仅运行 chmod) .