Oct. 4, 2023, 9:23 p.m. | Shaikh Al Amin

DEV Community dev.to

Create docker-compose file like the following:



version: '3.7'
services:
mongodb:
image: mongo:latest
container_name: mongodb_contaner
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 12345678
MONGO_INITDB_DATABASE: chat_app
command:
- '--logpath'
- '/var/log/mongodb/mongod.log'
ports:
- 27017:27017
volumes:
- ./docker/mongodb_data:/data/db
- ./docker/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js


Create a directory called docker like the following:



mkdir -p docker/mongodb_data


*Create an init-mongo.js inside docker directory and with the following content : *



db = db.getSiblingDB('admin');
db.auth('root', '12345678');

db = db.getSiblingDB('chat_app');
db.createUser({
user: 'app_user',
pwd: 'password',
roles: [
{
role: 'readWrite',
db: 'chat_app',
}, …

called command compose data directory docker entrypoint environment file image latest log mongo mongodb ports root run services ubuntu var version

Azure DevSecOps Cloud Engineer II

@ Prudent Technology | McLean, VA, USA

Security Engineer III - Python, AWS

@ JPMorgan Chase & Co. | Bengaluru, Karnataka, India

SOC Analyst (Threat Hunter)

@ NCS | Singapore, Singapore

Managed Services Information Security Manager

@ NTT DATA | Sydney, Australia

Senior Security Engineer (Remote)

@ Mattermost | United Kingdom

Penetration Tester (Part Time & Remote)

@ TestPros | United States - Remote