Base docker image to run a MongoDB database server.
To create the image your/repo
, execute the following command on the mongodb folder:
docker build -t your/repo 3.4/ .
Run the following command to start MongoDB:
docker run -d -p 27017:27017 -p 28017:28017 eddsuarez/mongodb
The first time that you run your container, a new random password will be set. To get the password, check the logs of the container by running:
docker logs <CONTAINER_ID>
You will see an output like the following:
========================================================================
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
Done!
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" eddsuarez/mongodb
You can now test your new admin password:
mongo admin -u admin -p mypass
curl --user admin:mypass --digest http://localhost:28017/
If you want to use another database with another user
docker run -d -p 27017:27017 -p 28017:28017 -e MONGODB_USER="user" -e MONGODB_DATABASE="mydatabase" -e MONGODB_PASS="mypass" eddsuarez/mongodb
You can now test your new credentials:
mongo mydatabase -u user -p mypass
Note: with mongo 3.x an admin user is also created with the same credentials
mongo admin -u user -p mypass
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 eddsuarez/mongodb
By default is "yes".
In MongoDB 3.4 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 eddsuarez/mongodb:3.4
By default is "wiredTiger".