gpt4 book ai didi

Docker 容器 - 用户数据

转载 作者:行者123 更新时间:2023-12-01 23:32:41 25 4
gpt4 key购买 nike

如果您使用 Docker 设置应用程序堆栈(在一个容器中或作为一系列链接的容器),迟早需要序列化用户数据 - 例如数据库。据我目前所见,这可以通过两种方式完成

  • 使用 -v 开关将主机上的卷映射到 Docker 容器。
  • 创建一个专用的数据容器,在需要时存储和恢复

这两种方法都没有问题 - 它们易于实现且工作正常。但是,有几件事我不清楚:

  • 当数据容器在实际写入数据的地方实际存在时。例如,写入该容器内/var/lib/mysql 文件夹的文件是否最终位于主机文件系统的某个位置?
  • 考虑到现在容器的用户可以直接写入主机的文件系统,将主机系统子文件夹作为卷映射到 Docker 容器有什么风险
  • 最后,有没有一种简单的方法可以限制映射卷的大小?

如果您对此有任何帮助,我将不胜感激。

最佳答案

When a data container is actually alive where the data actually being written. For example do the files written to the /var/lib/mysql folder inside that container end up somewhere on the host's file system?

未从主机挂载的卷存储在这里:/var/lib/docker/volumes/

What are the risks of mapping a host system sub folder as a volume on to the Docker container bearing in mind that now the container's user is able to write directly to the host's file system

只要您的容器不以 privileged 运行即,使用 --privileged=true 标志,您的容器无法访问设备,并且被锁定在主机 fs 的几个敏感部分之外。其次,默认情况下,docker 内的所有进程都以 root 身份运行,这赋予了它们在容器内的很多特权,并且由于 docker 不保证安全的沙箱,但可能有人会破解您容器内的进程。因此你应该使用 docker USER命令在你的 docker 文件或 -u标志以作为备用用户运行您的流程。

Finally, is there a simple way to limit the size of that mapped volume?

您必须在 docker 之外执行此操作,也许可以创建一个单独的逻辑驱动器并根据您的需要调整其大小。

关于Docker 容器 - 用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27796252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com