Mongorestore to a Docker container
Submitted by Patrick Coffey on Fri, 03/28/2014 - 20:12
I recently launched a Meteor based application that runs in a Docker container on a server running coreOS. I have a container running the node application, and a container running MongoDB. (Find an example of my Dockerfile for Meteor apps here).
When I first launched the application, I needed to copy up a bunch of mongo collections to the mongo container that I had running. It took me a minute to figure out how to do it, so I thought I'd share it:
#1 SSH into your server
ssh user@server.com -L 10000:mongo-container-port:mongo-container-port
Use -L
to forward a port on your machine (I picked 10000) to your mongo container.
#2 Run mongorestore
mongorestore -h localhost:10000 --db exampledbname /path/to/mongodump
Run mongorestore on the port on your machine that's forwarded to the mongo container on your server.
That's it! It's pretty easy to do :)