使用绑定挂载运行容器化的MongoDB [英] Running containerized MongoDB with bind mount
问题描述
我在OCI容器(docker.io/library/mongo)中运行MongoDB。我想在/ data / db(在Kubernetes看来是hostPath挂载)的容器内挂载一个主机目录。我不认为问题与Podman或Silverblue不兼容有关,但我在Fedora Silverblue(具有相同CLI的Docker替代品)上使用Podman。
I am running MongoDB in a OCI container (docker.io/library/mongo). I want to mount a host directory inside the container at /data/db (a hostPath mount in Kubernetes parlance). I am using Podman on Fedora Silverblue (a Docker alternative with the same CLI) though I don't think the problem is with Podman or Silverblue incompatibility.
使用:
podman run --name container_name -p=27017:27017 --mount type=bind,source=/path/to/dir,target=/data/db -d mongo
或
podman run --name container_name -p=27017:27017 -v /path/to/dir:/data/db -d mongo
容器退出并显示以下日志:
the container exits with to following logs:
cannot configure rootless cgroup using the cgroupfs manager
find: '/data/db': Permission denied
chown: changing ownership of '/data/db': Permission denied
容器中mongo用户的用户ID为999,我尝试将主机的目录更改为此用户,但这无济于事。我还尝试将主机的文件夹设置为具有全局读/写访问权限,但这仍然无济于事。
The user id for the mongo user in the container is 999 and I have tried changing the host's directory to this user but this does not help. I have also tried setting the host's folder to have global r/w access, but again this does not help.
推荐答案
事实证明,添加 relabel = shared
可使目录安装。因此命令变为
podman run --name container_name -p = 27017:27017 --mount type = bind,destination = / data / db,relabel = shared -d mongo
It turns out that adding relabel=shared
allows the directory to mount. So the command becomes
podman run --name container_name -p=27017:27017 --mount type=bind,destination=/data/db,relabel=shared -d mongo
这篇关于使用绑定挂载运行容器化的MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!