本文介绍了mongod在docker中运行后如何运行mongorestore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用docker设置mongodb-server,让其从Web下载转储并使用该信息填充它.我的问题是我可以让它运行并填充数据库,但是这样做之后,它就关闭了.

I'm trying to set up a mongodb-server with docker, let it download a dump from the web and populate it with that info. My problem is that I can make it run and fill the database, but after it's done that, it just closes.

这就是我解决问题的方式:

This was how I went about solving my problem:

sudo -u mongodb/usr/bin/mongod --config $ conf $ args&mongorestore转储

这里的问题是,如果 mongod 没有运行,我不能运行 mongorestore ,但是如果我以 mongod& ,则容器将在 mongorestore 完成运行后关闭.

The problem here is that I can't run mongorestore if mongod isn't running, but if I start mongod with mongod &, then the container will close down after mongorestore has finished running.

在我的 Dockerfile 中,我正在通过运行这些命令 CMD ["/etc/mongod/mongostart.sh"] .

In my Dockerfile, I'm running those commands by doingCMD ["/etc/mongod/mongostart.sh"].

推荐答案

启动mongod容器

docker run -d --name mymongod ... mongo ...

启动用于mongorestore的第二个容器,并将其链接到第一个容器:

Start a 2nd container for mongorestore, linking it to the first:

docker run --link mymongod:db ... mongo mongorestore -h db ...

mongorestore 将通过docker基于指定的-link 创建的别名 db 连接到 mymongod 容器.代码>

mongorestore will connect to the mymongod container via the alias db that docker creates based on the specified --link

这篇关于mongod在docker中运行后如何运行mongorestore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 19:17