Files for building MongoDB docker container.

Charles Reid 684588ef4b Fixing the build process to match rsync. Adding makefile, updating readme with instructions, and renaming build/run scripts. 1 month ago
scripts adding build/run scripts, and open fw script. 7 months ago
test adding info on how to get authentication credentials from docker logs, adding tests. 7 months ago
Dockerfile Fixing the build process to match rsync. Adding makefile, updating readme with instructions, and renaming build/run scripts. 1 month ago
LICENSE add MIT license 1 month ago
Makefile Fixing the build process to match rsync. Adding makefile, updating readme with instructions, and renaming build/run scripts. 1 month ago
README.md Fixing the build process to match rsync. Adding makefile, updating readme with instructions, and renaming build/run scripts. 1 month ago
build_mongodb.sh Fixing the build process to match rsync. Adding makefile, updating readme with instructions, and renaming build/run scripts. 1 month ago
close_fw.sh adding close fw script. 7 months ago
open_fw.sh adding build/run scripts, and open fw script. 7 months ago
run_mongodb.sh Fixing the build process to match rsync. Adding makefile, updating readme with instructions, and renaming build/run scripts. 1 month ago

README.md

d-mongodb

This repo contains files for creating a MongoDB Docker container.

TL; DR

Run make.

MongoDB Docker Image

This Docker container is based on the image from frodenas on github. The main change is that we are adding a build script and a run script, and a few tweaks to the Dockerfile.

To get the MongoDB authentication credentials for the docker container, check the logs using Docker - the credentials are printed to the logs.

$ docker logs inspiring_malachai

MongoDB Docker Image

Two scripts do the building and running of the Docker image. Don't call them directly - use the Makefile.

$ make

This should bind port 27017 from the host machine to port 27017 on the container.

Building the Docker Container

To build the Docker container, use the Makefile.

The build_mongodb.sh script will do the following:

  • Build the Docker container using the Dockerfile

Running the Docker Container

To run the Docker container, use the Makefile.

This script ask you to open the firewall of the machine running the Docker container to expose the container's service to the outside world.

The run_mongodb.sh script will do the following:

  • Mount /wifi in the host machine to /wifi in the container
  • Map port X on the host machine to port X in the container (X is specified as the first command line argument)

Container Actions

The Dockerfile will do the following:

  • Set up MongoDB aptitude repository for MongoDB 3.0
  • Mount local /opt/mongodb to container /data/db

Test MongoDB

The test/ directory contains two Python scripts to test out the MongoDB:

$ cd test/
$ python test_mongo_insert.py
$ python test_mongo_retrieve.py

Run them in that order.

Notes

User Credentials

The first time you run your container, a new user mongo with all privileges will be created with a random password. To get the password, check the logs of the container by running:

docker logs <CONTAINER_ID>

You will see an output like the following:

========================================================================
MongoDB User: "mongo"
MongoDB Password: "ZMUgiS3O1kJH1ec5"
MongoDB Database: "admin"
MongoDB Role: "dbAdminAnyDatabase"
========================================================================

If you want to preset credentials instead of a random generated ones, you can set the following environment variables:

  • MONGODB_USERNAME to set a specific username
  • MONGODB_PASSWORD to set a specific password

On this example we will preset our custom username and password:

$ docker run -d \
    --name mongodb \
    -p 27017:27017 \
    -e MONGODB_USERNAME=myusername \
    -e MONGODB_PASSWORD=mypassword \
    frodenas/mongodb

Databases

If you want to create a database at container's boot time, you can set the following environment variables:

  • MONGODB_DBNAME to create a database
  • MONGODB_ROLE to grant the user a role to the database (by default dbOwner)

On this example we will preset our custom username and password and we will create a database with the default role:

$ docker run -d \
    --name mongodb \
    -p 27017:27017 \
    -e MONGODB_USERNAME=myusername \
    -e MONGODB_PASSWORD=mypassword \
    -e MONGODB_DBNAME=mydb \
    frodenas/mongodb

Extra arguments

When you run the container, it will start the MongoDB server without any arguments. If you want to pass any arguments, just add them to the run command:

$ docker run \
	-d --name mongodb \
	-p 27017:27017 \
	mongodb \
	--smallfiles

Persistent data

MongoDB will store data in /data. Map /data to the host to keep data persistent.

$ mkdir -p /tmp/mongodb

$ docker run -d \
    --name mongodb \
    -p 27017:27017 \
    -v /tmp/mongodb:/data \
    mongodb