NoSQL MongoDB Volume Container

This series illustrates the steps necessary to convert an automation portal to a linked, operational series of Docker Containers. The Introduction for this series is at Linked Docker Containers TOC   .  The theory of operation of the automation portal is at Automation PortalThe Mode/View/Controller concept is a functional decomposition of the components of a portal app.  “Model” represents the code necessary to support a web framework such as FLASK or Django and functions for operating with a database or I/O. The View is of course the HTML necessary for a web portal. The Controller is the Angularjs code necessary to receive directives from the View, which in turn will access the Model for I/O operations.  An NoSQL backend is an applicable configuration archive and MongoDB is well suited for this.

Scope

This entry describes modifications to the MongoDB volume representation for containerization. The MongoDB volume must be accessible by the remote Model container’s Mongo client, in this instance without security authentication. . 

 

Dockerfile

The Docker Containerization of the MongoDB volume requires a Dockerfile, which will install all files and libraries (minus the kernel) necessary for the container to support the MongoDB service in the way that a hosted service would support the same functionality. The MongoDB volume Dockerfile is annotated as follows. Yes, this Dockerfile has test code and a few too many update/upgrade/restart statements. Optimize your production Dockerfile for efficiency.

############################################################
# Dockerfile to build Mongodb container images
# Based on Ubuntu
############################################################

# Set the base image to Ubuntu
FROM ubuntu:latest

# File Author / Maintainer
MAINTAINER Mike Pate

# Update the repository sources list
RUN apt-get update

################## BEGIN INSTALLATION ######################
#install curl
RUN apt-get install curl -y
#########create directory structure########
#
RUN mkdir /ContClBase
#
############ intsall Mongodb Prerequisites #########################
# import they key for the official MongoDB repository
RUN apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv EA312927
# add the MongoDB repository details
RUN echo “deb http://repo.mongodb.org/apt/ubuntuxenial/mongodb-org/3.2 multiverse” | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN apt-get update -y
########### Install Mongo db #####################
RUN apt-get install -y mongodb-org
# Update the repository sources list once more
RUN apt-get update -y
#
# copy hosts file additions to /etc/hosts
# COPY hosts /var/www/ContClBase/ContClBase/hosts
# expose mongodb default port
EXPOSE 27017
# copy cmd wrapper script containing copying of host file info plus python script
COPY mongod.conf mongod.conf
COPY wrapper.sh wrapper.sh
RUN apt-get upgrade -y
CMD ./wrapper.sh

 

MongoDB.Conf

 

The mongodb.conf file includes security authentication and permitted client information. This template permits any client to access the DB.

# mongod.conf

# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:

# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log

# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1

#processManagement:

security:
# authorization: ‘enabled’
#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

Wrapper.sh

Before a client can access the DB, the .conf file needs to be copied, the DB data directory needs to be created and Mongod must be started.
 
#!bin/bash
cp mongod.conf /etc/mongod.conf
mkdir data
mkdir data/db
mongod