Hi! My name is Christian, an Agile Software Developer, living in Trento (IT).
I am currently working at XPeppers.
Read more about me.

How to backup a mongodb database from a docker container to host

,
by

Share on Twitter

One of the recommended backup strategies of a mongodb database is through its tool called mongodump.

As I do it on pomodoro.cc, we will use it to dump the current consistent state of the database with all its collections and move it to the host machine for persistence.

Let’s say you have a docker container running a mongodb database with a volume on the host.

You can create a dump of the current state of the database with mongodump.

docker run --rm -it --link DOCKER_CONTAINER_NAME:mongo_alias -v /backup:/backup mongo mongodump --host mongo_alias --out /backup/

Updated as suggested by sokrat in the comments