Home

Awesome

Mongo Docker

Dockerfile and scripts to setup a production ready Mongo container with user authentication and SSL configuration

Example project https://github.com/duluca/lemon-mart-server

Key features:

Setup

MONGO_INITDB_ROOT_USERNAME=admin_user
MONGO_INITDB_ROOT_PASSWORD=admin_password
MONGODB_APPLICATION_DATABASE=app_db_name
MONGODB_APPLICATION_USER=app_user
MONGODB_APPLICATION_PASS=app_password

Quick Start

Note: To persist data you must link /data/db to a location where the data will persist if this image is stopped. See the yml file below as an example.

Sample Usage with docker-compose

Full source code: https://github.com/duluca/lemon-mart-server

docker-compose.yml

version: '3'

services:
  web-app:
    build: web-app
    ports:
      - '8080:3000'

  server:
    build: server
    environment:
      - MONGO_URI=mongodb://database/minimal-mean
    ports:
      - '3000:3000'
    depends_on:
      - database
    links:
      - database

  database:
    image: excellalabs/mongo
    env_file: .env
    ports:
      - '27017:27017'
    volumes:
      - '/my/own/datadir:/data/db'

Mounting to AWS EFS

If you're using AWS ECS as your container host, then your data needs to reside on AWS EFS. Setting this up correctly, so you can easily mount your '/data/db' volume to EFS can be complicated. Check out this step-by-step guide that will help you do just that, including how to create an AWS ECS Cluster from scratch.

TODO

Inspired by http://blog.bejanalex.com/2017/03/running-mongodb-in-a-docker-container-with-authentication/