Kingamere
Kingamere

Reputation: 10132

Docker mongodb - add database on disk to container

I am running Docker on windows and I have a database with some entries on disk at C:\data\db.

I want to add this database to my container. I have tried numerous ways to do this but failed.

I tried: docker run -p 27017:27017 -v //c/data/db:/data/db --name mongodb devops-mongodb

In my dockerfile I have:

RUN mkdir -p /data/db
VOLUME /data/db

But this doesn't add my current database on disk to the container. It creates a fresh /data/db directory and persists the data I add to it.

The docs here https://docs.docker.com/userguide/dockervolumes/ under 'Mount a host directory as a data volume' specifically told me to execute the -v //c/data/db:/data/db but this isn't working.

Any ideas?

Upvotes: 0

Views: 782

Answers (1)

thaJeztah
thaJeztah

Reputation: 29037

You're using Boot2Docker (which runs inside a Virtual Machine). Boot2Docker uses VirtualBox guest additions to make directories on your Windows machine available to Docker running inside the Virtual Machine.

By default, only the C:\Users directory (on Windows), or /Users/ directory (on OS X) is shared with the virtual machine. Anything outside those directories is not shared with the Virtual Machine, which results in Docker creating an empty directory at the specified location for the volume.

To share directories outside C:\Users\ with the Virtual Machine, you have to manually configure Boot2Docker to share those. You can find the steps needed in the VirtualBox guest addition section of the README;

If some other path or share is desired, it can be mounted at run time by doing something like:

$ mount -t vboxsf -o uid=1000,gid=50 your-other-share-name /some/mount/location

It is also important to note that in the future, the plan is to have any share which is created in VirtualBox with the "automount" flag turned on be mounted during boot at the directory of the share name (ie, a share named home/jsmith would be automounted at /home/jsmith).

Please be aware that using VirtualBox guest additions have a really bad impact on performance (reading/writing to the volume will be really slow). Which could be fine for development, but should be used with caution.

Upvotes: 2

Related Questions