|Charles Reid cca5d741d8 Update 'README.md'||2 months ago|
|scripts||11 months ago|
|test||10 months ago|
|Dockerfile||11 months ago|
|LICENSE||10 months ago|
|Makefile||11 months ago|
|README.md||2 months ago|
|build_mongodb.sh||11 months ago|
|close_fw.sh||11 months ago|
|open_fw.sh||11 months ago|
|run_mongodb.sh||10 months ago|
|startup_script.sh||10 months ago|
This repo contains files for creating a MongoDB Docker container.
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
Two scripts do the building and running of the Docker image. Don’t call them directly - use the Makefile.
This should bind port 27017 from the host machine to port 27017 on the container.
To build the Docker container, use the Makefile.
build_mongodb.sh script will do the following:
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.
run_mongodb.sh script will do the following:
The Dockerfile will do the following:
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.
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_USERNAMEto set a specific username
MONGODB_PASSWORDto 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
If you want to create a database at container’s boot time, you can set the following environment variables:
MONGODB_DBNAMEto create a database
MONGODB_ROLEto grant the user a role to the database (by default
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
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
$ docker run \ -d --name mongodb \ -p 27017:27017 \ mongodb \ --smallfiles
MongoDB will store data in
/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
A big huge waste of time working out some big huge stupid problems that were extremely difficult to track down. End lessons:
Lots of problems w/ things that would be set up the exact same way, then show different problems. That was a sign there might be issues with the Docker container being able to write to the files.
The data directory I was using (and have seen
online in several places) is
/data/db but this
was straight up wrong and caused me to lose all
my data. It should have been
Checked and had to fix permissions of the directory being shared as the data directory. Mongo user.
The lock file issues were resolved by turning on journaling with the --jorurnal flag, but issues still persisted.
Running interactively kept showing connection problems with localhost port 27017, these actually turned out to be file repair issues. So I found the repair flag.
After adding the repair step, had to work out the order. The repair step has to be called first and separate from everything in the first run script.
Fix the mongodb scripts to use journaling and repair stuff and not NOT use journaling, etc.
Call the included startup script
/etc/rc.local as a regular
user as follows:
su charles -c '/path/to/script.sh