Running containerized MongoDB with bind mount

可紊 提交于 2020-08-08 06:21:39

问题


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.

Using:

podman run --name container_name -p=27017:27017 --mount type=bind,source=/path/to/dir,target=/data/db -d mongo

or

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

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.


回答1:


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



来源:https://stackoverflow.com/questions/59557837/running-containerized-mongodb-with-bind-mount

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!