Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker mongodb config file

Tags:

docker

mongodb

There is a way to link /data/db directory of the container to your localhost. But I can not find anything about configuration. How to link /etc/mongo.conf to anything from my local file system. Or maybe some other approach is used. Please share your experience.

like image 638
ZuzEL Avatar asked May 06 '16 03:05

ZuzEL


People also ask

Where is MongoDB config file in Docker?

You can find one by entering the container and taking /etc/mongod. conf. orig or you can get it on MongoDB's GitHub repo: https://github.com/mongodb/mongo/blob/master/rpm/mongod.conf. By default, MongoDB will look for a configuration file in /etc/mongod.

Can I use MongoDB in Docker?

Can MongoDB Run in a Docker Container? MongoDB can run in a container. The official image available on Docker Hub contains the community edition of MongoDB and is maintained by the Docker team. This image can be used in a development environment.

How do I access Docker in MongoDB?

You can connect to MongoDB on localhost:27017 . Then use the following command to open the MongoDB shell. I have used mymongo as an arbitrary container name, though you can replace mymongo with test-mongo or any other container name of your choosing. The show dbs command will display all your existing databases.


2 Answers

I'm using the mongodb 3.4 official docker image. Since the mongod doesn't read a config file by default, this is how I start the mongod service:

docker run -d --name mongodb-test -p 37017:27017 \  -v /home/sa/data/mongod.conf:/etc/mongod.conf \  -v /home/sa/data/db:/data/db mongo --config /etc/mongod.conf 

removing -d will show you the initialization of the container

Using a docker-compose.yml:

version: '3' services:  mongodb_server:     container_name: mongodb_server     image: mongo:3.4     env_file: './dev.env'     command:         - '--auth'         - '-f'         - '/etc/mongod.conf'     volumes:         - '/home/sa/data/mongod.conf:/etc/mongod.conf'         - '/home/sa/data/db:/data/db'     ports:         - '37017:27017' 

then

docker-compose up 
like image 143
Argeo P. Avatar answered Sep 21 '22 21:09

Argeo P.


When you run docker container using this:

docker run -d -v /var/lib/mongo:/data/db \  -v /home/user/mongo.conf:/etc/mongo.conf -p port:port image_name 

/var/lib/mongo is a host's mongo folder.

/data/db is a folder in docker container.

like image 24
Thanh Nguyen Van Avatar answered Sep 20 '22 21:09

Thanh Nguyen Van