Docker MongoDB

Docker Mongodb

docker pull mongo
docker run mongo (server mode only run , we can not intract)
To interact with running container :
1. open new command prompt
2. docker exec -it bash (or) docker exec -it sh
3. ps -e
4. To intract with “mongod”(server) through mongo shell(client), through which we execute query
5. docker inspect => path:”docker-entrypoint.sh”, args:[“mongod”]

host name : [ec2-user@abc~] cd /usr/local/bin => /# ls
this will not have anything

docker exec -it 467 bash
now this will go to container

root@467: /# ls /usr/local/bin => cd /usr/local/bin
root@467:/usr/local/bin # cat docker-entrypoint.sh

it will have docker-entrypoint.sh(shell script file )
/# cd /usr/bin
/# ls (it has mongo,mongod…etc mongo related files)
/# exit (exit from container)
[ec2-user@abc~]$
[ec2-user@abc~]$ mongo => command not fond, because host machine does not have mongo shell
[ec2-user@abc~]$ docker exec -it 467 mongo //to get into container to execute mongoshell
> db.version()
> show dbs
> use testdb
> db.courses.insert({“Devops”:”docker”})
> db.finde({})
Every container has individual isolate unit, until we remove the container it will have the database even it is in stopped mode

6. [ec2-user@abc~]$ docker exec -it 467 bash
root@467: /# ls data/db (database location)
exit
7. [ec2-user@abc~]$ pwd
/home/ec2-user

[ec2-user@abc~]$ mkdir mongo
[ec2-user@abc~]$ cd mongo
[ec2-user@abc mongo]$ mkdir db
[ec2-user@abc mongo]$ ls
[ec2-user@abc mongo]$ docker stop 467 (stop existing container)
[ec2-user@abc mongo] docker run -d -v $PWD/db:/data/db mongo (run new mongo container)
[ec2-user@abc mongo] cd db
[ec2-user@abc db]$ ls or [ec2-user@abc db]$ ls or ls -la
now it will have 3 new mongodb files

Leave a Reply

Your email address will not be published. Required fields are marked *