Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount external volume for mongoDB using docker-compose and docker-machine

I would like to persist the mongoDB data outside of the container and on a specified volume. I am using docker-compose and the yml file looks like

web:   build: .   command: python -u app.py   ports:     - "5000:5000"   volumes:     - .:/todo   links:     - db db:   image: mongo:3.0.2 
like image 477
casra Avatar asked Dec 21 '15 06:12

casra


People also ask

How can I access a MongoDB container from another container?

If you need to access the MongoDB server from another application running locally, you will need to expose a port using the -p argument. Using this method, you will be able to connect to your MongoDB instance on mongodb://localhost:27017 . You can try it with Compass, MongoDB's GUI to visualize and analyze your data.

How do I link my local docker to MongoDB?

For connecting to your local MongoDB instance from a Container you must first allow to accept connections from the Docker bridge gateway. To do so, simply add the respective gateway IP in the MongoDB config file /etc/mongod. conf under bindIp in the network interface section.

How does MongoDB run in docker container from host?

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.


1 Answers

As documented on the docker hub page for that image (https://hub.docker.com/_/mongo/) you can use

volumes:   - './data:/data/db' 

Which will use the host path ./data

like image 192
dnephin Avatar answered Sep 27 '22 15:09

dnephin