Kingamere
Kingamere

Reputation: 10122

Docker - unable to mount start mongodb in container - operation not permitted

I am running docker on windows and I am trying to add the database that is on my disk into the mongodb container.

The database is stored in C:\Users\data\db.

I run the command:

$ docker run --name mongodb -p 27017:27017 -v //c/Users/data/db:/data/db devops-mongodb

But then I get this error:

2015-08-17T14:28:10.385+0000 [initandlisten] exception in initAndListen: 10309 U
nable to create/open lock file: /data/db/mongod.lock errno:1 Operation not permi
tted Is a mongod instance already running?, terminating

I believe I have set the permissions correctly in the Dockerfile like this:

RUN mkdir -p /data/db && chown -R `id -u` /data/db

VOLUME /data/db

Upvotes: 2

Views: 2437

Answers (2)

Vince Bowdren
Vince Bowdren

Reputation: 9208

Main answer: Docker Machine

If you're running Docker on Windows (in 2015), then you must be running it using Docker Machine. This is because Docker does not yet run natively on Windows; instead it uses a virtual computer in VirtualBox and docker runs on this instead.

Now the crucial thing is that the host (Windows) folders shared with Docker are done through this VirtualBox machine, which means they use a virtual file system vfs - not ntfs or xfs or any of the file systems as normally understood.

And the problem with this vfs file system is that it doesn't have all the features which MongoDB requires; see the docs on MongoDB Platform Specific Considerations :

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

So when you try to run MongoDB in a docker container on Windows, using a volume mapping to a shared windows folder, it won't work because the VirtualBox's intermediate file system isn't capable of supporting MongoDB file system commands.

Appendix: Native Docker on Windows 10

From Windows 10 onwards, there is a new option to run Docker on Windows natively without using Docker Machine or VirtualBox. However, there is again a problem with the file system; it uses ntfs shared over smb, which again does not support all the file operations which MongoDB needs, and leads to similar Operation Not Supported errors.

Upvotes: 1

Hatem Jaber
Hatem Jaber

Reputation: 2402

Try adding the -d flag and see if that works, like so:

docker run -d --name mongodb -p 27017:27017 -v //c/Users/data/db:/data/db devops-mongodb

Upvotes: 0

Related Questions