Has anyone tried to use Vagrant with persistent storage?

272 views
Skip to first unread message

Andy

unread,
Jul 16, 2018, 6:04:59 PM7/16/18
to mongodb-user
I haven't been able to find any examples that use Vagrant and also try to persist the data. For postgres and MySQL, I would typically do this with a docker image and docker commands. For some reason, all examples have used a provisioning script to setup Mongodb which is fine but any attempt to use local storage in place of vm storage hasn't worked.

I have tried...

1) replace the conf and defined the datadb directory to be a folder in the vagrant mapped folder. If I then try to create a database, I get an error that mongo is unable to find data/db which is not my defined directory or the default on unbuntu

sudo cp /vagrant/mongod.conf /etc
sudo chown mongodb:mongodb /vagrant/db/data
sudo service mongod start
sudo systemctl enable mongod.service

And in conf

storage:
dbPath: /vagrant/db/data
logPath: /vagrant/db/logs

2) I also tried to symlink but mongo still used the default directory

sudo ln -s /vagrant/db/data /var/lib/mongodb
sudo chown mongodb:mongodb /vagrant/db/data
sudo service mongod start
sudo systemctl enable mongod.service

Has anyone done this successfully and able to help?

Robert Cochran

unread,
Jul 16, 2018, 9:10:27 PM7/16/18
to mongodb-user
Hi!

I use Vagrant, and have not yet tried to format an SSD as ab XFS volume and then make it available to a MongoDB as it runs on a Vagrant box. I am guessing that we both need to study the Vagrant documentation for this. 

Under every Vagrant box is really a VirtualBox instance that is running, and it might be that we have to set up parameters through VirtualBox to enable direct pass-through to hardware devices which are running on the host. I'm not sure; I've never done that yet.

I do not have extended experience with Vagrant. I first started using it when I took a MongoDB University course, M036, and that course expected students to use Vagrant. Since then, I have come to like Vagrant because I can use it on the command line. I seem to have plenty of space within my Vagrant boxes for MongoDB and various databases and many collections. That works for me. I can shut down the Vagrant box (`'vagrant halt') and start it up again (`vagrant up') and then ssh into the box and start MongoDB, and all my data is there. 

Thanks so much

Bob

Andy

unread,
Jul 17, 2018, 2:38:53 PM7/17/18
to mongodb-user
Thanks Bob!

I'd like to maintain state outside of the VM so that I can recreate the VM when necessary without losing the state.  I've found that to be pretty handy and I've gotten it to work with other databases but it has been through setting it up with Docker in Vagrant.  I'll give that a try.

Robert Cochran

unread,
Jul 17, 2018, 8:12:01 PM7/17/18
to mongodb-user
You may find this helpful:


There are also some gists out there (GitHub style "gists") which discuss variations on this topic, but I have not taken the time to study the gists and the comments and think about what is being suggested and said.


Bob
Reply all
Reply to author
Forward
0 new messages