我的 docker mongo 镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo latest f03be0dc25f8 2 days ago 448MB
我的容器命令
docker run -it --name c1_mongo -p 37017:27017 -v /var/mongo/data/c1_mongo:/data/db -v /var/mongo/config/c1_mongo/mongod.conf.orig:/etc/mongod.conf.orig -v /var/mongo/logs/c1_mongo:/var/log/mongodb mongo -f /etc/mongod.conf.orig
我遇到的错误
{"t":{"$date":"2021-03-29T11:00:02.967Z"},"s":"F", "c":"CONTROL", "id":20574, "ctx":"main","msg":"Error during global initialization","attr":{"error":{"code":38,"codeName":"FileNotOpen","errmsg":"Failed to open /var/log/mongodb/mongod.log"}}}
- 我已成功将容器内数据目录的卷设置为我的主机
- 我已成功将容器内配置文件的卷设置为我的主机
- 设置日志音量失败。
当我更改主机中的配置文件并运行容器时,所有更改都会反射(reflect)在容器中的配置文件中。我的容器的/data/db 目录中的数据正在同步到主机中我各自的文件夹。
就像我的数据存储在我的主机中一样。我希望我的日志也存储在我的主机上。
注意:卷映射显示主机和容器的目录。
请帮忙!
最佳答案
可以使用以下步骤解决此问题。
- Run the container without mounting the volume which is causing the issue.
- Go into container bash and check the folder permission on which you are facing issue in my case it is /var/log/mongodb
- Now check the owner of the folder.
- run "cat passwd" in container shell and find that owner you found in last step and note the id against it could be(999 or 1000 etc).
- Now exit the container, stop it, remove it.
- Now on your host log path which in my case is /var/mongo/data/c1_mongo
- Change the owner of c1_mongo folder to, "chown -R 999:999 c1_mongo" (999 is the id you found in step 4)
- Now run your container again.
关于mongodb - 无法在 docker 容器中设置 mongodb 日志的卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66853303/