Reputation: 718
I am attempting to script some setup for Mongo instances in a Docker compose file. I seems as if the second command never runs (which should initiate this container as a primary in a repl set). Here is my command:
docker run -d mongo /bin/bash -c "mongod --replSet \"test\"; mongo --eval \"rs.initiate({_id:'test',members:[{_id:0,host:'localhost:27017'}]})\""
When I then exec in to the container and do an rs.config, it says intiate has not been ran. So, how do I go about issuing multiple commands to the startup of a Mongo container?
Upvotes: 0
Views: 868
Reputation: 1098
It looks like you're starting the mongo daemon as the first command.
Are you sure this command returns ? It doesn't seem to finish executing before you "docker exec" in the container. That could be why the second command isn't executed.
Maybe try to put the command in "background" with "&"
docker run -d mongo /bin/bash -c "mongod --replSet \"test\" &; mongo --eval \"rs.intiate({_id:'test',members:[{_id:0,host:'localhost:27017'}]})\""
Upvotes: 1