32

When starting the image I get the following error:

 2019-02-27T17:09:41.095+0000 E STORAGE  [initandlisten] WiredTiger error (17) [1551287381:95206][1:0x7fae36fc4a40], connection: __posix_open_file, 715:
/data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1551287381:95206][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-02-27T17:09:41.108+0000 I STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.6
2019-02-27T17:09:41.111+0000 E STORAGE  [initandlisten] WiredTiger error (1) [1551287381:111166][1:0x7fae36fc4a40], connection: __posix_open_file, 715:
/data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1551287381:111166][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-02-27T17:09:41.149+0000 E STORAGE  [initandlisten] WiredTiger error (17) [1551287381:149030][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1551287381:149030][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-02-27T17:09:41.153+0000 I STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.7
2019-02-27T17:09:41.156+0000 E STORAGE  [initandlisten] WiredTiger error (1) [1551287381:156133][1:0x7fae36fc4a40], connection: __posix_open_file, 715:
/data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1551287381:156133][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-02-27T17:09:41.177+0000 E STORAGE  [initandlisten] WiredTiger error (17) [1551287381:177375][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1551287381:177375][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-02-27T17:09:41.192+0000 I STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.8
2019-02-27T17:09:41.194+0000 E STORAGE  [initandlisten] WiredTiger error (1) [1551287381:194762][1:0x7fae36fc4a40], connection: __posix_open_file, 715:
/data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1551287381:194762][1:0x7fae36fc4a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-02-27T17:09:41.200+0000 W STORAGE  [initandlisten] Failed to start up WiredTiger under any compatibility version.
2019-02-27T17:09:41.200+0000 F STORAGE  [initandlisten] Reason: 1: Operation not permitted
2019-02-27T17:09:41.201+0000 F -        [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 704

The .env folder value is

MONGO_SAVE_PATH=./database/db

The DB docker file:

FROM mongo:latest
VOLUME ["/data/db"]
WORKDIR /data
EXPOSE 27017
CMD ["mongod"]

The docker-compose.yml DB container

services:
  my-mongo-db:
  build: ./database
  ports:
   - 32815:27017
  volumes:
- ./database/db:/data/db

I'm not sure how to fix this. However, on linux and Mac this issue doesn't appear.

David
  • 640
  • 1
  • 7
  • 15

5 Answers5

40

WARNING (Windows & OS X): The default Docker setup on Windows and OS X uses a VirtualBox VM to host the Docker daemon. Unfortunately, the mechanism VirtualBox uses to share folders between the host system and the Docker container is not compatible with the memory mapped files used by MongoDB (see vbox bug, docs.mongodb.org and related jira.mongodb.org bug). This means that it is not possible to run a MongoDB container with the data directory mapped to the host.

Answer from docker mongo GitHub

Workaround to persist data:

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

More info here

Augustas
  • 1,167
  • 21
  • 31
  • thank you for your reply but I'm not using virtual box I'm using VM. – David Apr 29 '19 at 23:04
  • 2
    This answer still holds true even with the default distro of desktop docker on windows using Hpyer-V. Use the docker volume create and you will be fine. – Gordon Jun 23 '19 at 05:51
  • Is there a way to change the commands above in order to work with docker-compose, I am getting the same issue: https://stackoverflow.com/questions/61147270/docker-compose-and-mongodb-failed-to-start-up-wiredtiger-under-any-compatibilit – java12399900 Apr 10 '20 at 19:33
18

If you are using docker-compose then following is the way replicate the answer above.

services:
  mongodb_container:
    ...
    volumes:
      - mongodata:/data/db
volumes:
  mongodata:

Please note that the sample above indicates only needed parts of the yml file for the mongodb storage.

charitha
  • 361
  • 3
  • 9
  • 2
    hi where does the mongodata volume end up being mapped to in windows? – Paul Jun 11 '20 at 13:02
  • @paul Unlike bind mounts volumes doesn't map to any windows folder location directly. It is completely managed by docker. – charitha Jun 12 '20 at 05:49
  • Thanks for the answer. I guess you just copy out any files manually if you want to persist them? – Paul Jun 12 '20 at 12:50
  • @paul Actually docker volumes are persistent. They don't get deleted unless you explicitly delete them. Getting data out of it is another story. May be you could you a data backup tool for Mongo – charitha Jun 13 '20 at 01:21
  • And gues what? Data is not persisted between `docker-compose up` runnings – chill appreciator Aug 06 '20 at 11:00
  • @standalone That's bit strange. They don't go off with the containers. They should be removed explicitly. – charitha Aug 12 '20 at 12:18
  • @charitha actually, you was right and it works. I was missing `--build` flag. So to apply changes and fully restart exist containers we need to do `docker-compose up --build` – chill appreciator Aug 17 '20 at 23:07
  • 1
    don't forget to put `version: '3'` above `services` – realsarm Sep 04 '20 at 14:46
  • 1
    There should be another blank line after `mongodata:` else there seems to a error thrown by compose version 2.3 – bmabir17 May 29 '21 at 12:43
5

Although Augustas is right, but I found this answer particularly useful with docker-compose.yml.

What you can do as a workaround is:

  1. Create a .env file in the same path as your docker-compose file and store the current path in an environment variable like this:
MONGO_HOST_DATA=/Users/user123/MyMongoProject //path to mongo data folder (for C:\Users\user123\MyMongoProject)
  1. Now, in your docker-compose file, replace the above-mentioned variable:
    services:
      my-mongo-db:
      build: ./database
      ports:
       - 32815:27017
      volumes:
    - ${MONGO_HOST_DATA}/database/db:/data/db
  • If you want to see how the actual path replaced the environment variable, you can use the following command:
docker-compose config

Additionally, if you use any disk drive other than C:\ you might want to change the Docker file sharing settings:

Windows Docker settings window

Hope this helps.

Babak
  • 1,274
  • 15
  • 18
  • Hi I tried this but i couldnt get it to work. I created a file called .env in the folder next to the docker-compose.yml but it still doesnt work. Is there any way to test the .env file is being read? Im using asp.net core in visual studio – Paul Jun 10 '20 at 16:31
  • Yes, actually, as I also mentioned about, you can run `docker-compose config`. It should show you the the actual file content after all the placeholders replaced by the actual values – Babak Jun 11 '20 at 01:08
  • Thanks for the help. I got this working in the end, but mongo still throws the same errors. I can see it writing all the WiredTiger.wt.2 files (with the number going up). is there anything else that could be wrong? – Paul Jun 11 '20 at 13:04
  • It depends on what kind of error you're getting. Can you check the logs using `docker logs `? – Babak Jun 11 '20 at 15:10
  • 1
    thanks for the help. i created a new question so i could include the logs. https://stackoverflow.com/questions/62345030/unable-to-run-a-mongodb-container-in-docker-for-windows-using-linux-file-system . The log file repeats the lines i pasted – Paul Jun 12 '20 at 13:14
2

For me, the issue was caused by NTFS permissions while running Mongo on WSL2. Moving to ext4 (WSL partition) fixed it.

martinx
  • 21
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31240018) – Juan Fontes Mar 12 '22 at 10:44
  • That was my exact problem. I was running my container under WSL, but using a folder located in my local NTFS drive. As soon as I started my docker environment in a ext4 WSL partition, everything worked as a charm. – Geziel Carvalho Sep 04 '22 at 15:29
  • This does indeed provide an answer to the question. Nice work! I don't know what triggered it, because it had been working find on my NTFS partition (`/mnt/c/...`) until it didn't. – datu-puti Jun 27 '23 at 12:45
0

Not entirely the same issue, but I saw the same error messages when simply spinning up a Docker container for mongo in Ubuntu and attempting to mount an existing directory to the container:

docker run --name some-mongo -p 27017:27017 -v $PWD/db-data:/data/db -d mongo

In my case the errors only showed up if I was trying to run the command from a directory on my mounted HDD, and I was able to solve it by migrating my codebase with the /db-data directory to my SSD where Ubuntu is installed.

adamgy
  • 4,543
  • 3
  • 16
  • 31