Boot2Docker (on Windows) 运行 Mongo with shared folder (不支持此文件系统)

Boot2Docker (on Windows) running Mongo with shared folder (This file system is not supported)

我正在尝试使用 Boot2Docker 在 Windows 上使用共享文件夹启动 Mongo 容器。当开始使用 run -it -v /c/Users/310145787/Desktop/mongo:/data/db mongo 时,我在容器内收到一条警告消息:

WARNING: This file system is not supported.

启动后mongo立即关闭。

关于如何解决这个问题的任何提示或技巧?

显然,according to this gist and Sev (sevastos)、mongo 不支持通过 VirtualBox 共享文件夹挂载卷:

See mongoDB Productions Notes:

MongoDB requires a filesystem that supports fsync() on directories.
For example, HGFS and Virtual Box’s shared folders do not support this operation.

the easiest solutions of all and a proper way for data persistance is Data Volumes:

Assuming you have a container that has VOLUME ["/data"]

# Create a data volume
docker create -v /data --name yourData busybox true
# and use
docker run --volumes-from yourData ...

这并不总是理想的(但以下是 Mac,作者 Edward Chu (chuyik)):

I don't think it's a good solution, because the data just moved to another container right?
But it still inside the container rather than local system(mac disk).

I found another solution, that is to use sshfs to map data between boot2docker vm and your mac, which may be better since data is not stored inside linux container.

Create a directory to store data inside boot2docker:

boot2docker ssh
mkdir -p /mnt/sda1/dev

Use sshfs to link boot2docker and mac:

echo tcuser | sshfs docker@localhost:/mnt/sda1/dev <your mac dir path> -p 2022 -o password_stdin

Run image with mongo installed:

 docker run -v /mnt/sda1/dev:/data/db <mongodb-image> mongod

corresponding boot2docker issue points out to docker issue 12590 ( Problem with -v shared folders in 1.6 #12590),它指向 使用双斜杠 的解决方法。

using a double slash seems to work. I checked it locally and it works.

docker run -d -v //c/Users/marco/Desktop/data:/data <image name>

it also works with

docker run -v /$(pwd):/data

您似乎不需要 MongoDb 的数据目录,从 docker-composer.yml 中删除这些行应该 运行 没有问题。

数据目录仅被mongo用于缓存。

作为解决方法,我只是在 mongo 守护程序启动之前从文件夹中复制。另外,在我的例子中,我不关心日志文件,所以我只复制数据库文件。

我在 docker-compose.yml 上使用了这个命令 command: bash -c "(rm /data/db/*.lock && cd /prev && cp *.* /data/db) && mongod" 每次停止我使用的容器之前: docker exec <container_name> bash -c 'cd /data/db && cp $(ls *.* | grep -v *.lock) /prev'

注意:/prev 被设置为一个卷。 path/to/your/prev:/prev

另一个解决方法是使用 mongodump 和 mongorestore。

  • 在 docker-compose.yml 中:command: bash -c "(sleep 30; mongorestore --quiet) & mongod"
  • 在终端中:docker exec <container_name> mongodump

注意:我使用sleep是因为我想确保mongo启动了,这需要一段时间。

我知道这涉及手动工作等,但我很高兴至少我在我的 Windows 10 机器上得到了 mongo 和现有数据 运行,并且仍然可以继续工作我的 Macbook 当我想要的时候。