[英]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"}}}
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.可以使用以下步骤解决此问题。
- 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
Go 进入容器 bash 并检查在我的情况下您遇到问题的文件夹权限是 /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).
在容器 shell 中运行“cat passwd”并找到您在上一步中找到的所有者并注意它的 id 可能是(999 或 1000 等)。
- Now exit the container, stop it, remove it.
现在退出容器,停止它,移除它。
- Now on your host log path which in my case is /var/mongo/data/c1_mongo
现在在您的主机日志路径上,在我的情况下是 /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)
将 c1_mongo 文件夹的所有者更改为“chown -R 999:999 c1_mongo”(999 是您在步骤 4 中找到的 id)
- Now run your container again.
现在再次运行您的容器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.