Skip to content

Instantly share code, notes, and snippets.

@grammy-jiang
Last active October 7, 2022 13:37
Show Gist options
  • Save grammy-jiang/cf6652f74b23c60677c57da6ea6b19a7 to your computer and use it in GitHub Desktop.
Save grammy-jiang/cf6652f74b23c60677c57da6ea6b19a7 to your computer and use it in GitHub Desktop.
MongoDB dump and restore within Docker

MongoDB dump and restore within Docker

MongoDB dump

prompt the user for password

foo@bar:~$ docker run --interactive --tty --rm --network=<network> --volume=<volume>:/tmp \
  mongo:latest \
  mongodump \
    --host <host> --port <port> \
    --db <database> \
    --username <username> --password "" \
    --authenticationDatabase <database> \
    --archive=/tmp/mongodump

otherwise, give the password

foo@bar:~$ docker run --interactive --tty --rm --network=<network> --volume=<volume>:/tmp \
  mongo:latest \
  mongodump \
    --host <host> --port <port> \
    --db <database> \
    --username <username> --password <password> \
    --authenticationDatabase <database> \
    --archive=/tmp/mongodump

MongoDB Restore

foo@bar:~$ docker run --interactive --tty --rm --network=<network> --volume=<volume>:/tmp \
  mongo:latest \
  mongorestore \
    --host <host> --port <port> \
    --db <database> \
    --username <username> --password "" \
    --authenticationDatabase <database> \
    --archive=/tmp/mongodump

Reference

Docker

MongoDB Dump and Restore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment