gpt4 book ai didi

docker --volumes-from 不挂载任何文件

转载 作者:行者123 更新时间:2023-12-02 18:05:17 24 4
gpt4 key购买 nike

我有两个容器,其中一个我使用 gluster 文件系统将我需要的文件挂载到我容器的 mnt 目录中,我在我的 Dockerfile 中使用 VOLUME/mnt 来共享音量。我用这个运行这个容器:

docker run -d --cap-add SYS_ADMIN --device=/dev/fuse:/dev/fuse -e MOUNTPOINT="server1:test" -e TARGET="/mnt"  --name gluster gluster-client

我想在作为 nginx 容器的第二个容器中使用此文件,因此我使用 --volumes-from 运行此容器以使用该共享卷,这就是我运行容器的方式:

docker run -it --volumes-from gluster  nginx sh

我的 gluster 容器工作正常,我的意思是我检查了挂载目录(这里是/mnt)并且我可以看到文件,但是在我使用的第二个容器中 docker --volumes-from/mnt 目录中没有文件, 貌似可以挂载目录但不能挂载那些目录下的文件,我该如何解决?,是因为我使用的是gluster还是什么?

gluster容器基于fedora,nginx容器基于alpine。

感谢您的帮助:)

最佳答案

这可能是由于 SELinux。尝试将第二个容器运行为

docker run -it --volumes-from gluster:z  nginx sh

来自 docker run reference documentation :

Labeling systems like SELinux require that proper labels are placed on volume content mounted into a container. Without a label, the security system might prevent the processes running inside the container from using the content. By default, Docker does not change the labels set by the OS.

To change the label in the container context, you can add either of two suffixes :z or :Z to the volume mount. These suffixes tell Docker to relabel file objects on the shared volumes. The z option tells Docker that two containers share the volume content. As a result, Docker labels the content with a shared content label. Shared volume labels allow all containers to read/write content. The Z option tells Docker to label the content with a private unshared label. Only the current container can use a private volume.

关于相同的论点,您可以在 Using Volumes with Docker can Cause Problems with SELinux 上找到更多详细信息和 Practical SELinux and Containers .

编辑:如果那不是原因,您的问题应该是由于 glusterfs 和数据容器。尝试使用命名卷。

将第一个容器中的 VOLUME 行更改为

VOLUME myVolume:/mnt

在第二个容器中,您可以使用 --volume=myVolume 而不是 --volumes-from

Docker Data Containers and Named Volumes 上查看有关数据容器和命名卷的更多信息和 Docker named volume explained .

关于docker --volumes-from 不挂载任何文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41771533/

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