简体   繁体   English

将 Mongo 数据库导入 Docker 容器

[英]Import a Mongo Database into a Docker Container

I have a docker container generated from a docker image which has mongoDB installed.我有一个docker container ,它是从安装了mongoDBdocker image生成的。 I want to export a database from my local machine and import it into that docker container .我想从本地机器导出数据库并将其导入到docker container

What're the steps for that?那有什么步骤?

I tried to export the whole db by mongodump and then copy the dump file into the container with docker cp .我尝试通过mongodump导出整个数据库,然后使用docker cp将转储文件复制到容器中。 But feels like that's not the correct way.但感觉这不是正确的方法。

Thanks in advance.提前致谢。

You don't need to copy the file.您不需要复制文件。 As long as you can access mongo on a port that's open, just use mongorestore from the comfort of your local machine, eg只要您可以在打开的端口上访问 mongo,只需在本地机器上舒适地使用 mongorestore,例如

mongodump --uri 'mongodb://localhost:27017/yourdatabase' --archive=<your file> --gzip
mongorestore --uri 'mongodb://remotehost:27017/yourdatabase' --archive=<your file> --gzip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM