How To Backup a MongoDB Database From a Docker Container

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

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.

Open your Terminal:


Run the following commands:

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