MongoDB docker image with a shell script wrapper that has some conveniences. This is based on Tutum's docker container.
Running the MongoDB server
Run the following command to start MongoDB:
docker run -d -p 27017:27017 -p 28017:28017 wayblazer/mongodb
You can run the docker logs command to see initialization information about the container.
docker logs <CONTAINER_ID>
You will see output with the WayBlazer insignia at the top. You should see output from the shell script, Supervisord, and initial user information like:
======================================================================== You can now connect to this MongoDB server using: mongo admin -u admin -p 5elsT6KtjrqV --host <host> --port <port> Please remember to change the above password as soon as possible! ========================================================================
In this case,
5elsT6KtjrqV is the password set.
You can then connect to MongoDB:
mongo admin -u admin -p 5elsT6KtjrqV
Setting a specific password for the admin account
If you want to use a preset password instead of a randomly generated one, you can
set the environment variable
MONGODB_PASS to your specific password when running the container:
docker run -d -p 27017:27017 -p 28017:28017 -e MONGODB_PASS="mypass" wayblazer/mongodb
You can now test your new admin password:
mongo admin -u admin -p mypass curl --user admin:mypass --digest http://localhost:28017/
Run MongoDB without password
If you want to run MongoDB without password you can set the environment variable
AUTH to specific if you want password or not when running the container:
docker run -d -p 27017:27017 -p 28017:28017 -e AUTH=no wayblazer/mongodb
By default is "yes".
Creating Other Users
Ideally, we want to create other users with different access credentials to different databases outside the 'baked' container, so we're not storing hardcoded usernames and passwords. The best way to do this is to use the
create_mongodb_users script in the container:
docker run --rm wayblazer/mongodb ./create_mongodb_users.sh <mongo_hostname> <database> <admin_user> <admin_password> <new_user_to_create> <password_for_new_user>
Here we leverage the same container (no overhead) to connect to the mongodb server container and run the CLI against it using the admin user/pass created above. It will create the users and exit, removing the temporary containers.
Run MongoDB with a specific storage engine
In MongoDB 3.0 there is a new environment variable
STORAGE_ENGINE to specific the mongod storage driver:
docker run -d -p 27017:27017 -p 28017:28017 -e AUTH=no -e STORAGE_ENGINE=mmapv1 wayblazer/mongodb:3.0
By default is "wiredTiger".
Change the default oplog size
In MongoDB 3.0 the variable
OPLOG_SIZE can be used to specify the mongod oplog size in megabytes:
docker run -d -p 27017:27017 -p 28017:28017 -e AUTH=no -e OPLOG_SIZE=50 wayblazer/mongodb:3.0
By default MongoDB allocates 5% of the available free disk space, but will always allocate at least 1 gigabyte and never more than 50 gigabytes.
Known Issues and Gotchas
- Boot2Docker (VirtualBox VM) does not support memory mapped disk data so you can't mount mongo data directly to you mac file system when running locally. You have to use a directory on your Boot2Docker VM. It is advised to use the same container as long as possible to avoid having to re-load data into the container. http://stackoverflow.com/questions/29818433/boot2docker-on-windows-running-mongo-with-shared-folder-this-file-system-is-n. This is not a problem with linux (production) systems.