How to run mongorestore after mongod in docker

青春壹個敷衍的年華 提交于 2021-02-08 20:54:06

问题


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 dump

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.

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


回答1:


Start your mongod container

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

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

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

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



来源:https://stackoverflow.com/questions/31118159/how-to-run-mongorestore-after-mongod-in-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!