问题
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