Skip to content

Basic configuration and persistence #235

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

Closed
KevinBurton opened this issue Jan 15, 2018 · 7 comments
Closed

Basic configuration and persistence #235

KevinBurton opened this issue Jan 15, 2018 · 7 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@KevinBurton
Copy link

I understand that on OSX and Windows I cannot use -v. I guess I am not clear how the database "persists" when each new container. Is it possible to detail the full path for where the database will be for OSX?
How do I pass configuration information if I cannot use -v? Where is the configuration information maintained/persisted for each new container. The only thing in the documentation is to check the official documentation on the configuration options. Ideas?

@yosifkit
Copy link
Member

On OSX and Windows you can use a named volume so that docker will persist the data to the VM's hard disk: -v my-mongo-data:/data/db/. You can then manage the volume life-cycle with docker volume subcommands.

As for config, you can just pass them in as the command to the image and they will get passed along to mongod (https://docs.mongodb.com/manual/reference/program/mongod/):

$ docker run -d -v mongo-data:/data/db/ mongo --replSet my-replica 

@KevinBurton
Copy link
Author

Is there a better way? What if there are a lot of configuration settings? A configuration file is not supported?

@KevinBurton
Copy link
Author

I am not sure how to interpret this warning:

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.

https://hub.docker.com/_/mongo/

@yosifkit
Copy link
Member

The warning is that on OSX/Windows you are not running mongod natively on the host, but in a VM and any folders shared between VM and Host do not support the filesystem access that mongod requires. In short, it will fail to run if you do something like the following:

$ docker run -d -v /path/on/osx/:/data/db/ mongo

You can add a config file as a flag (it can be put anywhere in the container that the mongo user can access):

$ docker run -d -v mongo-data:/data/db/ -v /path/to/config/:/etc/mongo/ mongo --config /etc/mongo/mongo.conf

(this one could use better docs 😞)

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Apr 25, 2018
@wglambert
Copy link

Question seems sufficiently answered and hasn't had any responses in some months so I'm going to prune.

The docs now have a subsection: 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 . . .

https://github.com/docker-library/docs/tree/master/mongo#where-to-store-data

@KevinBurton
Copy link
Author

So the answer is to use a named volume to persist that data? It seems that text configuration file can be used so you can pass in a configuration via a shared volume. I am not clear what the --config does.

@wglambert
Copy link

A named volume is independent of the host filesystem
To try for a concise explanation: https://stackoverflow.com/a/34357861
For nuance on volumes vs bind mounts MariaDB/mariadb-docker#120 (comment)

https://docs.mongodb.com/v3.4/reference/program/mongod/#cmdoption-configsvr
--config is to specify the file for runtime options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

3 participants