2

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

My problem is about why if I changed the dbpath in mongo.conf file and share it to my docker using a volume, but the data is always saved inside /data/db when I set /mnt/sda1/data/db. How do I change this behaviour ?
Sorry, my guess was that the config file was not found because of an error in the volume definition. I updated the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.