Skip to content

Instantly share code, notes, and snippets.

@dianjuar
Last active September 10, 2019 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dianjuar/ef988110e96a919976e8f15158ea1ddd to your computer and use it in GitHub Desktop.
Save dianjuar/ef988110e96a919976e8f15158ea1ddd to your computer and use it in GitHub Desktop.
Dockerized Mongo DB environment

Dockerized MongoDB environemnt

A quick an simple dockerized Mongo DB setup

Set up

  1. Create this docker-file in your project.
# Use root/example as user/password credentials
version: '3.1'

services:

  mongo:
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
    image: mongo:xenial
    ports:
      - 27017:27017
    volumes:
      - ./db-api-data:/data/db

  mongo-express:
    environment:
      ME_CONFIG_MONGODB_SERVER: mongo
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
    depends_on:
      - mongo
    image: mongo-express
    links:
     - mongo
    ports:
      - 8081:8081
    restart: on-failure
  1. Create these npm scripts for easy management
{
  "db:start": "docker-compose up",
  "db:stop": "docker-compose stop",
}
  1. Add this to your .gitignore file
# Database
/db-api-data

Instructions

  • To turn on the database execute npm run db:start
  • To turn off the database execute npm run db:stop
  • Visit localhost:8081 to manage your DB graphically
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment