dev-resources.site
for different kinds of informations.
How to run mongodb using docker-compose in ubuntu
Published at
10/4/2023
Categories
mongodb
docker
dockercompose
ubuntu
Author
shaikhalamin
Author
12 person written this
shaikhalamin
open
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',
},
],
});
db.createCollection('test_docker');
Run docker-compose to start running the container:
docker-compose down && docker-compose build --no-cache && docker-compose up -d
To check everything is working, SSH into the MongoDB container like the following:
//to SSH into the container
docker exec -it mongodb_contaner bash
mongod --version
//Check admin db connection is working or not
mongosh admin -u root -p
// check default database with newly created by init-mongo.js
show dbs
dockercompose Article's
30 articles in total
Want to Learn Docker in Advance Way?
read article
deploy Jenkins using docker compose with production ready
read article
Docker Advance Part 2: Docker Logging
read article
A Simple Guide to Docker Compose & Multi-Container Applications
read article
Dockerize nestjs app with postgres
read article
Tips and Tricks for Docker Compose: Leveraging the override Feature
read article
Dockerize nestjs application with Postgres
read article
RabbitMQ container with Docker Compose
read article
Quick and simple Local WordPress Setup for Lazy Developers
read article
Bug: Docker-compose up?
read article
How to resolve Docker Compose Warning WARN[0000] Found orphan containers
read article
How to resolve Docker Compose Warning WARN[0000] Found orphan containers
read article
How To Set Up Docker SeleniumΒ GRID
read article
How to Ensure Docker Compose Uses Environment Variables from the `.env` File
read article
Essential Docker Commands for Developers
read article
[Docker] How to fix 'host not found in upstream "host.docker.internal"'.
read article
Como configurar imagem Docker(PHP e Nginx) para projetos Laravel com PHP 8.3
read article
Containerize your multi-services app with docker compose
read article
αααααΆαααα»αα’αααΈαααΆαα α’αα αααα»α Docker compose.
read article
Installation of Docker Compose:
read article
MongoDB containers with Docker Compose
read article
An Overview of Docker Compose and its Features.
read article
How to change docker root data directory and why would you want to do that (hint: to optimize space)
read article
Containerize a Web Application using docker compose
read article
O Docker Compose agora tem uma V2, veja como instalar
read article
Vue 2 vite dockerized steps
read article
An Advanced Guide (2) to Docker: Managing Multi-Container Applications π³
read article
How to run mongodb using docker-compose in ubuntu
currently reading
How to run postgres database using docker and docker-compose
read article
Easy Dockerization with Docker INIT
read article
Featured ones: