问题
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