mongodb - 无法在 docker 容器中设置 mongodb 日志的卷

标签 mongodb docker containers

我的 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"}}}
  1. 我已成功将容器内数据目录的卷设置为我的主机
  2. 我已成功将容器内配置文件的卷设置为我的主机
  3. 设置日志音量失败。

当我更改主机中的配置文件并运行容器时,所有更改都会反射(reflect)在容器中的配置文件中。我的容器的/data/db 目录中的数据正在同步到主机中我各自的文件夹。

就像我的数据存储在我的主机中一样。我希望我的日志也存储在我的主机上。

注意:卷映射显示主机和容器的目录。

请帮忙!

最佳答案

可以使用以下步骤解决此问题。

  1. Run the container without mounting the volume which is causing the issue.
  2. Go into container bash and check the folder permission on which you are facing issue in my case it is /var/log/mongodb
  3. Now check the owner of the folder.
  4. 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).
  5. Now exit the container, stop it, remove it.
  6. Now on your host log path which in my case is /var/mongo/data/c1_mongo
  7. Change the owner of c1_mongo folder to, "chown -R 999:999 c1_mongo" (999 is the id you found in step 4)
  8. Now run your container again.

关于mongodb - 无法在 docker 容器中设置 mongodb 日志的卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66853303/

相关文章:

c++ - 通过引用函数传递映射时出错

linux - 了解技术(Docker)容器架构

继承类类型的 C++ 容器

MongoDB:如何查询字段为空或未设置的记录?

java - 我如何修改 mongodb 查询以适应集合结构

docker - 无法生成错误 “shim error: docker-runc not installed on system”的Docker镜像

git - docker 在包含 Dockerfile 的私有(private) git 存储库上构建?

mongodb错误: how do I make sure that your journal directory is mounted

node.js - 基于NodeJS的网站推荐框架

javascript - 保存后JavaScript中的隐藏字符