This question is asked frequently.
How do I backup and restore a mongo DB in a docker container.
We first need to find the container label. You may need sudo for the following commands.
docker ps -a
So we need to do this:
docker exec docker_mongo_1 sh -c 'mongodump --archive' > db.dump
And in the current directory you should find db.dump
Restore should be the reverse process:
docker exec -i docker_mongo_1 sh -c 'mongorestore --archive' < db.dump
This is quite a good guide though I couldn’t get the compose variant to work (and my test container is built with compose)