The current version (3.2.0) of this image contains
Notes to persistence
If you stop the docker container, everything on the containers filesystem is lost! That isn't really good for a database container :-) But luckily it is possible to mount directories from the Host into the docker container, so called volumes. That is the place there you can store data permanently.
MongoDB stores his files by default into the
/data directory. By starting the docker container you can mount a host directory into
/data. Let's call that persistent host directory
You have to add a
mongod.conf file in the root of
YOUR_LOCAL_DATA_DIR. The instance expects their the main configuration file. If the file
mongod.conf is not their the container will exit with an error code!
You can run it like this:
> docker run --name mongodb -v <YOUR_LOCAL_DATA_DIR>:/data -p 27017:27017 > -p 28017:28017 -d reiz/mongodb:1.0.2
> docker run --name mongodb -v /mnt/mongodb:/data -p 27017:27017 > -p 28017:28017 -d reiz/mongodb:1.0.2
In that example
YOUR_LOCAL_DATA_DIR there should be a
db directory. MongoDB is expecting that. If that subdirectory is missing the container will exit with an error code.
By default the container will log to stdout and you can watch the logs with this command
> docker logs mongodb
If you want to persist the logs add this line to your
And create a
logs directory under
YOUR_LOCAL_DATA_DIR. Than all the logs will be written to
Here is the Dockerfile I used to build this image: https://gist.github.com/reiz/a2b76b37279c4fd11287