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:0x7fae
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 not that the sample above indicates only needed parts of the yml file for the mongodb storage.
Although Augustas is right, but I found this answer particularly useful with docker-compose.yml
.
What you can do as a workaround is:
.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)
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
docker-compose config
Additionally, if you use any disk drive other than C:\ you might want to change the Docker file sharing settings:
Hope this helps.
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
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.