Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDb doesn't start when using volumes #138

Closed
survivant opened this issue Oct 10, 2016 · 19 comments
Closed

MongoDb doesn't start when using volumes #138

survivant opened this issue Oct 10, 2016 · 19 comments

Comments

@survivant
Copy link

I'm trying to start mongo using volume to persist the data between restarts.

I been in Docker Settings and check the C: checkbox and enter credentials.

when I start mongo db using this command line :
$ docker run -p 27017:27017 -v c:/test-mongo:/data/db mongo

I obtain the error below

2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=b08b1c94b8b2
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] db version v3.2.10
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] modules: none
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] build environment:
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] distmod: debian81
2016-10-10T19:48:32.036+0000 I CONTROL [initandlisten] distarch: x86_64
2016-10-10T19:48:32.037+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-10-10T19:48:32.037+0000 I CONTROL [initandlisten] options: {}
2016-10-10T19:48:32.048+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-10-10T19:48:32.063+0000 E STORAGE [initandlisten] WiredTiger (1) [1476128912:63941][1:0x7f7cbb986cc0], connection: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2016-10-10T19:48:32.065+0000 I - [initandlisten] Assertion: 28595:1: Operation not permitted
2016-10-10T19:48:32.066+0000 I STORAGE [initandlisten] exception in initAndListen: 28595 1: Operation not permitted, terminating
2016-10-10T19:48:32.066+0000 I CONTROL [initandlisten] dbexit: rc: 100

if I check in teh HD, I'll see that some file were created
2016-10-10 03:48 PM

.
2016-10-10 03:48 PM ..
2016-10-10 03:48 PM journal
2016-10-10 03:48 PM 0 mongod.lock
2016-10-10 03:48 PM 46 WiredTiger
2016-10-10 03:48 PM 21 WiredTiger.lock
2016-10-10 03:48 PM 0 WiredTiger.wt
4 File(s) 67 bytes

BUT

if I use this command line :

docker volume create --name=mongodata
docker run -d -p 27017:27017 -v mongodata:/data/db mongo

it will works

$ docker run -p 27017:27017 -v mongodata:/data/db mongo
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=01d5334620b9
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] db version v3.2.10
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] modules: none
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] build environment:
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] distmod: debian81
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] distarch: x86_64
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-10-10T19:54:39.093+0000 I CONTROL [initandlisten] options: {}
2016-10-10T19:54:39.098+0000 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-10-10T19:54:39.098+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-10-10T19:54:39.306+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2016-10-10T19:54:39.306+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-10-10T19:54:39.306+0000 I NETWORK [initandlisten] waiting for connections on port 27017

@survivant
Copy link
Author

the problem using volume is that I can't share files : like logs. I need to be able to see the files that the application will generate.

@survivant
Copy link
Author

I'm using Windows 10 PRO

c:>ver

Microsoft Windows [Version 10.0.14393]

$ docker version
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 17:52:38 2016
OS/Arch: windows/amd64

Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 17:52:38 2016
OS/Arch: linux/amd64

@simonferquel
Copy link

The problem is that mounting volumes from a Windows directory is done using samba/cifs, and that mongo db has certain requirements on the filesystem that are not fulfilled by cifs (ability to exclusively lock a file, msync, fsync....).

I suggest that you mount your folder somewhere else in the container, and create a symlink so that logs (and logs only) are rerouted to that share

@survivant
Copy link
Author

thanks @simonferquel for the explanation. Can you help me clarify what as to be done on my side ? I saw the problem often in few forums but never a complete working solution.

here my setup : windows 10 with the latest docker using hyper-v.

I want to share a folder on my windows be to able to exchange files/dump with mongodb.

using the command line : docker run -v c:/temp:/data/db mongo
will generate the previous error.

with docker volume create mongodata
docker run -v mongodata:/data/db mongo will starts
but the files will be saved in a volume within docker.

there is a way to transfer file from windows into the volume "mongodata" ?

or do I have to create a symlink in windows 10 using mklink ?
something like this :
Using mklink to create a directory symbolic link:

F:\test>mklink /d test-dir-sym-link test

and I use this instead

docker run -v c:/test:/data/db mongo ?

@stfgit
Copy link

stfgit commented Oct 11, 2016

You can succeed by running :
docker run -p 27017:27017 -v /userlogin/dockerVolMongo/db:/data/db mongo

Assuming you shared succesfully C drive in docker settings (using userlogin credentials) and you are logged in as userlogin :

image

The windows host directory will be located at:
C:\Users**userlogin**_dockerVolMongo_\db

@survivant
Copy link
Author

@stfgit if I use that command it works.. but it produce the same results at creating a volume with : docker create volume...

if I try that : docker run -p 27017:27017 -v c/Users/Sebastien/mongovol/db:/data/db mongo
c:>docker run -p 27017:27017 -v c/Users/Sebastien/mongovol/db:/data/db mongo
docker: Error response from daemon: create c/Users/Sebastien/mongovol/db: "c/Users/Sebastien/mongovol/db" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.
See 'docker run --help'.

but if I use this syntax :

c:>docker run -p 27017:27017 -v /Users/Sebastien/mongovol/db:/data/db mongo
or
docker run -p 27017:27017 -v /Sebastien/mongovol/db:/data/db mongo

mongo will launch.. BUT there will still doesn't have file save on the host, only in the container.

if I check in the folder :
$ pwd
/c/Users/Sebastien

there is no folder mongovol.

thanks

@survivant
Copy link
Author

I try with symbolic link but I got a new error

c:\test>mklink /d mongozzz c:\test\xyz

C:\test>docker run -p 27017:27017 -v c:/test/mongozzz:/data/db mongo
docker: Error response from daemon: mkdir /c/test/mongozzz: file exists.

@simonferquel
Copy link

Hmm I was thinking the other way around (mounting a Linux volume, into /data/db, a windows volume in /mongologs, and making a symlink in a docker file from the log folder in /data/db to the windows volume). In any case, data files can't be stored directly in the Windows volume.

But what I did instead, was creating a dockerfile based on the mongo image, declare a new volume /data/logs and add parameters to mongod to push logs in this volume and mount a windows volume in it. So now I have:
/data/db and /data/configdb stored in Linux persisted volumes (in the Linux VM VHD), and logs directly in my c:\mongologs.

If I need to backup the data, I can either rely on mongodump/mongorestore.

@simonferquel
Copy link

Here is the dockerfile:

FROM mongo:3.2.10
RUN mkdir -p /data/logs \
    && chown -R mongodb:mongodb /data/logs
VOLUME /data/logs
CMD ["mongod", "--logpath", "/data/logs/mongo.logs"]

I built the image with docker build -t mymongo .
and run it with docker run -d --name mongo -v C:\mongologs:/data/logs mymongo

Now I can user docker start|stop mongo to start or stop my server

@simonferquel
Copy link

If you want to be able to directly copy your data directory to another machine (without mongodump), you can create a named volume that you mount in /mongo/db, and while your mongo container is stopped, mount the same named volume in a separate container and copy it to a windows mounted volume.

On the target machine, you just do the exact opposite.

@survivant
Copy link
Author

thanks @simonferquel for the workaround. I'll try the dockerfile solution. I was just hopping that could be solved internally with docker/mongo with buildin support.

One thing that I didn't try. could it works if we mount a SMB drive in Win10 and use it as volume for mongodb ?

@simonferquel
Copy link

That is exactly what the "Drive sharing" feature does, and unfortunately, Linux SMB support is not rich enough to support MongoDB. Another solution is to work with windows containers instead of Linux (which requires windows 10 anniversary update) and use a flavor of mongo working on Windows like mongo:windowsservercore. But we do not support (yet!) networking between Windows and Linux containers

@simonferquel
Copy link

@survivant Are you ok if I close this issue ?

@survivant
Copy link
Author

yes.

zazabe added a commit to zazabe/cm that referenced this issue Jun 14, 2017
zazabe added a commit to zazabe/cm that referenced this issue Jun 14, 2017
zippy1981 added a commit to zippy1981/unifi-docker that referenced this issue Aug 25, 2018
If you run this container on docker for windows and mount the mongo files as a local volumne, [mongo will crash because it can't fsync the data files](docker/for-win#138).

For whatever reason this causes the curl command to hang forever and the container will eat all your CPU.
jacobalberty pushed a commit to jacobalberty/unifi-docker that referenced this issue Sep 4, 2018
If you run this container on docker for windows and mount the mongo files as a local volumne, [mongo will crash because it can't fsync the data files](docker/for-win#138).

For whatever reason this causes the curl command to hang forever and the container will eat all your CPU.
@danzaharescu
Copy link

Hello Everybody,

I came to the same problem as of may 2019.
I am using the 1809 image.
If anybody is still interested in a solution/workaround (because nothing else works for me) this could be:

Delete the mongod.lock and WiredTiger.lock from the file system (volume)
Not sure if it is the cleanest solution, but the only one that seems to work...

@putnap
Copy link

putnap commented Aug 13, 2019

It seems that you can't mount a drive to mongo container on Windows because VirtualBox shared file system doesn't support fsync()
https://docs.mongodb.com/manual/administration/production-notes/#fsync-on-directories

However, what you can try is to create a volume that is mounted to a file system and use that for mongo container. I will give it a try later today. I'm using docker-compose for my application so this should be a good enough solution for dev.

@renntbenrennt
Copy link

Hey everybody, are there any solutions pertinent to this

"Mongo fail to mount to host when it's in Windows container" issue???

I can make mongo mount to the host if I am using linux container but I got some issues that I can access the data from the remote address, meaning that even if I "-p 27017:27017" in the command,
I can't use tools like dbeaver to connect to the mongo in the container.

I have the feeling that I should look for the solution that "how can I access linux container remotely" instead...

Exhausting.... using this container thing....

@danzaharescu
Copy link

Hy SeasonLeee,
You may try my workaround described above: "Delete the mongod.lock and WiredTiger.lock from the file system (volume)" - before mongo starts (can be done with a script inside the container, that is called when you need, before mongo starts...)

@docker-robott
Copy link
Collaborator

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked

@docker docker locked and limited conversation to collaborators Jun 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants