Create Dump of MongoDB on Windows using Docker Machine

10 April 2016 - Docker

Recently, I have been doing some programming work using the MEAN stack (Mongo, Express, Angular, Node). I use a Windows 10 PC as my dev box and host my Mongo databases on Mongo Labs (mLabs) in Azure. I need to create dumps as backups. In this blog article I summarize how I do that with Docker Machine.

Docker Machine

First, get Docker onto your Windows box by using Docker Machine. At the day of writing, Virtual Box comes with Docker Machine automatically. I uninstall it after installing Docker Machine as I prefer to use my local Hyper-V instead.

Once you got Docker Machine, you can create your first docker host. As mentioned, I use Hyper-V for that. Therefore, I used the Hyper-V driver of Docker Machine. So the command looks something like this:

docker-machine create --driver hyperv default

Verify that everything is up and running using docker info and docker pull mongo (pulls down the MongoDB image from Docker Hub).

Run mongodump in Docker Container

Now we can use mongodump inside a Docker Container to create our dump:

docker run --rm -v /opt/backup:/opt/backup mongo mongodump --host --port 42898 --db yourDb --username your_user --password y0urP@ssw0rd! --out /opt/backup/mongo-backup
Note that the command uses a Docker Volume Mapping to store the Mongo dump in the host's /opt/backup/ folder.

Use FileZilla to transfer the dump

Last but not least you can use FileZilla to transfer the dump from your Docker Host to your Windows box. Here are the settings you need:

  • Server: Get the IP address by using the command docker-machine ls
  • Protocol: SFTP - SSH File Transfer Protocol
  • User: docker
  • Logon Type: Key file
  • Key File: C:\Users\your.user\.docker\machine\machines\default\id_rsa

That's it. Three simple steps and you have your Mongo dump on your Windows dev box.