我正在尝试在我的 Windows 机器上运行一个 docker-compose
来启动一个 MongoDB 实例和一个 data-只有 容器代理包含数据库文件的附加卷。
mongodata:
image: mongo:2.6.8
volumes:
- ./data/db:/data/db
command: --break-mongo
mongo:
image: mongo:2.6.8
volumes_from:
- mongodata
ports:
- "27017:27017"
command: --smallfiles --rest
*附注--break-mongo 命令是有目的的,因为它只需要创建卷
据我了解,使用 data-only
卷模式可以处理权限问题,但我可以在 Mongo 容器启动期间看到以下错误:
[0m2016-01-26T00:23:52.340+0000 [initandlisten] info preallocateIsFaster couldn't run due to: couldn't open file /data/db/journal/tempLatencyTest for writing errno:1 Operation not permitted; returning false
[0m2016-01-26T00:23:52.341+0000 [initandlisten] Unable to remove temporary file due to: boost::filesystem::remove: Text file busy: "/data/db/journal/tempLatencyTest"
[0m2016-01-26T00:23:52.344+0000 [initandlisten] exception in initAndListen: 13516 couldn't open file /data/db/journal/j._0 for writing errno:1 Operation not permitted, terminating
因此,我无法通过本地计算机的附加卷使用 MongoDb。有什么办法解决这个问题吗?
最佳答案
If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory. So, you can mount files or directories on OS X using.
docker run -v /Users/<path>:/<container path> ...
On Windows, mount directories using:
docker run -v /c/Users/<path>:/<container path> ...
All other paths come from your virtual machine’s filesystem. For example, if you are using VirtualBox some other folder available for sharing, you need to do additional work. In the case of VirtualBox you need to make the host folder available as a shared folder in VirtualBox. Then, you can mount it using the Docker -v flag.
基本上,要么尝试提供从您的 C:\Users
开始的完整路径如上所示的文件夹,或者如果你不能拥有它,请将主机文件夹设为 Virtualbox 中的共享文件夹。
更新
无需给出完整路径。 docker-compose
会处理的。你必须确保你的 docker-compose.yml
在你的 Users
的内部(某处)文件夹。它不能在某个根文件夹中。如果您已经这样做了,那么您将不得不调整您的权限。只需授予该文件夹的完全权限即可。
关于mongodb - Docker 无法通过纯数据容器启动带有附加卷的 MongoDb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35005096/