A quick an simple dockerized Mongo DB setup
- 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
- Create these npm scripts for easy management
{
"db:start": "docker-compose up",
"db:stop": "docker-compose stop",
}
- Add this to your
.gitignore
file
# Database
/db-api-data
- 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