I wanted to transfer (aka clone or copy) a strapi.io database that was using mongodb from one mongodb docker container to another mognodb docker container. Here is what I ended up with:
- Enter the source docker container:
docker exec -it portal_mongo_1 bash
- Use
mongodump
to create a database archive
mongodump --uri="mongodb://strapi@localhost:27017/portal?authSource=admin" --archive="mongodump-portal"
- Exit and copy the archive from docker to host:
docker cp portal_mongo_1:/mongodump-portal .
- Transfer the archive whenever the destination container is. For example in my case I used
scp
to copy it to another server.
- Copy the archive from host to the destination docker:
docker cp mongodump-portal mongo1:/data
- Enter the destination docker container:
docker exec -it mongo1 bash
- Restore it using
mongorestore
:
mongorestore --uri="mongodb://username@localhost:27017/portal?authSource=admin" --archive="mongodump-portal" --nsFrom='portal.*' --nsTo='portal.*'
Comments