Robert
Robert

Reputation: 10953

Docker mongo image always save the data inside /data/db directory

I am using docker image for mongo. I changed the directory where I want to save my data inside the mongo.conf file:

dbpath=/mnt/sda1/data/db/

Also I am using docker-compose to create my development environment:

mongo:
  image: mongo
  ports:
   - 27017:27017
  volumes:
   - $HOME/Desktop/development/mongo/data/:/mnt/sda1/data/db/
   - $HOME/Desktop/mongo/config/mongod.conf:/etc/mongod.conf.orig
  command: mongod --smallfiles

When I go inside my mongo container and I check the /mnt/sda1/data/db directoy, it is empty and then go to /data/db and the data is here.

I don't understand why the data isn't inside the directory /mnt/sda1/data/db is I defined it has the dbpath for mongo configuration file.

Upvotes: 2

Views: 2340

Answers (1)

Alexis N-o
Alexis N-o

Reputation: 3993

Seems that you are naming the config file /etc/mongod.conf.orig inside the container. You probably should name it /etc/mongod.conf.

Also, unlike docker run, you can use relative path for the volume option in your docker-compose.yml file and don't have to use $HOME.

Upvotes: 1

Related Questions