简体   繁体   English

无法为 docker 容器中的 mongodb 日志设置音量

[英]Unable to set volume for mongodb logs in docker container

My docker mongo images我的 docker mongo 图像

REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
mongo        latest    f03be0dc25f8   2 days ago   448MB

My container command我的容器命令

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

The error I am getting我得到的错误

{"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. I have successfully set the volume for my data directory inside the container to my host我已成功将容器内数据目录的卷设置为我的主机
  2. I have successfully set the volume for my config file inside the container to my host我已成功将容器内的配置文件的音量设置为我的主机
  3. Setting the volume for the log is failing.设置日志卷失败。

When I change my config file in the host and run the container so my all changes get reflected in my config file in the container.当我更改主机中的配置文件并运行容器时,我的所有更改都会反映在容器中的配置文件中。 And data in my container's /data/db directory is being synced to my respective folder in the host.我容器的 /data/db 目录中的数据正在同步到主机中我各自的文件夹。

Just like my data if being stored in my host.就像我的数据存储在我的主机中一样。 I want my logs to be stored on my host as well.我希望我的日志也存储在我的主机上。

Note: volume mapping showing the directories of both host and container.注意:卷映射显示主机和容器的目录。

Please Help!请帮忙!

This issue can be resolved using the following steps.可以使用以下步骤解决此问题。

  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 Go 进入容器 bash 并检查在我的情况下您遇到问题的文件夹权限是 /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).在容器 shell 中运行“cat passwd”并找到您在上一步中找到的所有者并注意它的 id 可能是(999 或 1000 等)。
  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现在在您的主机日志路径上,在我的情况下是 /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)将 c1_mongo 文件夹的所有者更改为“chown -R 999:999 c1_mongo”(999 是您在步骤 4 中找到的 id)
  8. Now run your container again.现在再次运行您的容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到Docker容器中的mongodb - Unable to connect to mongodb in docker container 无法使用相同的共享卷运行多个mongodb docker容器 - Can't run multiple mongodb docker container with same shared volume 已解决:如何创建没有卷的Mongodb docker容器 - Resolved: How to create a Mongodb docker container without volume 无法连接到在 docker 容器中运行的 mongoDB - Unable to connect to mongoDB running in docker container 无法在 azure 容器实例中将 azure 文件共享挂载为 mongodb 卷 - Unable to mount azure file shares as mongodb volume in azure container instances 初始化Docker容器中的MongoDB副本集时出错 - Error initialising MongoDB replica set in Docker container 无法从容器内部连接到在 docker 容器中运行的 mongodb 实例 - Unable to connect to the mongodb instance running in a docker container from inside the container Nodejs应用程序docker无法连接到mongodb docker容器 - Nodejs application docker unable to connect to mongodb docker container 无法从外部连接到在 docker 容器中运行的 mongodb 实例 - Unable to connect to the mongodb instance running in a docker container from outside 无法在 docker 中为 windows 使用 ZE206A54E97690CCE50CC872DD42Z 文件系统运行 mongoDb 容器 - unable to run a mongoDb container in docker for windows using linux file system
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM