davorb
davorb

Reputation: 660

How to run mongorestore after mongod in docker

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"].

Upvotes: 4

Views: 2933

Answers (1)

cpuguy83
cpuguy83

Reputation: 5993

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

Upvotes: 4

Related Questions