5

I have the following docker command

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

and I get the following error response from docker / mongo

MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8706cbf1b78f
db version v3.4.2
git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: debian81
    distarch: x86_64
    target_arch: x86_64
options: {}
wiredtiger_open config: create,cache_size=478M,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),
WiredTiger error (1) [1489982988:687653][1:0x7fec9df0ccc0], connection: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
Assertion: 28595:1: Operation not permitted src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
exception in initAndListen: 28595 1: Operation not permitted, terminating
shutdown: going to close listening sockets...
removing socket file: /tmp/mongodb-27017.sock
shutdown: going to flush diaglog...
now exiting
shutting down with code:100

now when I remove the volume mongo works but I need to persist my data so I need to mount the volume somehow, just not sure what i am doing wrong at this point.

I do see the files appearing in my folder but not sure why I get the 100 error

Logan Murphy
  • 6,120
  • 3
  • 24
  • 42
  • Persisting data through the VM layer will be slow and can cause problems like this. Can you use a named/local volume? `docker run -c mongo_data:/data/db mongo` – Matt Mar 20 '17 at 05:09
  • 1
    This won't work; MongoDB and mapped volumes in Docker on Windows are not compatible, as noted in the [mongo docker image documentation](https://hub.docker.com/_/mongo/). Note: this question has been raised and answered before, for example at http://stackoverflow.com/q/42756776/174843 – Vince Bowdren Mar 20 '17 at 13:09
  • @VinceBowdren i saw that but there are 2 ways listed above to mount, I wasnt sure if both mounting methods were impossible due to my os – Logan Murphy Mar 20 '17 at 14:38
  • @VinceBowdren is it possible to mount for linux but not mount for windows using docker-compose file? – Logan Murphy Mar 20 '17 at 15:07
  • @LoganMurphy Yes, MongoDB can use docker mapped volumes on linux hosts without problems (subject to [some other technical requirements](https://docs.mongodb.com/manual/administration/production-notes/#platform-specific-considerations)) – Vince Bowdren Mar 20 '17 at 15:24
  • @VinceBowdren what i meant to ask was, can i conditionally mount for linux but not mount for windows using docker-compose only (or some other widely accepted method)...i dont want to have to change my code between environments and if i do mount on windows mongodb will crash – Logan Murphy Mar 20 '17 at 20:14
  • I don't know of any conditionality in docker-compose, no. But I would question if you really _want_ your application to be cross-platform; both [MongoDB](https://docs.mongodb.com/manual/administration/production-notes) and [Docker](https://docs.docker.com/engine/userguide/storagedriver/selectadriver/) interact with the OS's file system in complex ways, so it would probably be useful if you could figure out precisely which one precise platform is best suited to your needs, and stick to that. – Vince Bowdren Mar 20 '17 at 22:05
  • Possible duplicate of [How do I configure mongo to run in docker to using an external drive on windows](https://stackoverflow.com/questions/42756776/how-do-i-configure-mongo-to-run-in-docker-to-using-an-external-drive-on-windows) – Nicolas Seiller Apr 02 '18 at 12:47

1 Answers1

3

To get around this, you can employ a tool like rsync to move the db files into mapped directory while Mongo is running. The underlying bug has to do with latency between the Windows mapped volume and that bind path within the container. Offloading the work to rsync decouples the latency from Mongo's runtime requirements.

Example

Create a basic Dockerfile like this:

FROM mongo:latest

RUN apt-get update && \ 
    apt-get install -y \
        rsync

ADD init.sh /init.sh

Where init.sh is:

#!/bin/bash

migrate_db() {
  while true
  do
    rsync -avh /data/db/* /data/mapped-db
    sleep 5
  done
}

migrate_db &

#Execute a command
mongod --smallfiles --logpath=/dev/null --verbose &

#Wait
wait $!

Then, when launching the container, just start with ./init.sh as your ENTRYPOINT.

deepelement
  • 2,457
  • 1
  • 25
  • 25