1

I need to create a Dockerfile starting mongodb and initiating replicaset after that.

First I created a Dockefile as below:

FROM mongo:latest 
EXPOSE 27017 
ADD setup.sh /root/setup.sh 
CMD ["bash","/root/setup.sh"] 

Then I created the setup.sh file like this:

#!/bin/bash 
mongod --fork --replSet rs0 --noprealloc --smallfiles 
sleep 5 
mongo --eval "rs.initiate()"

The problem is that it´s not working, am I doing something wrong?

Thanks!

Bruno Ornelas
  • 331
  • 1
  • 3
  • 14
  • 1
    Hi Bruno Omelas; you should know that there have been previous questions in the past about trying to use docker to automatically initiate a replica set; I recommend you take a look at my answer here, strongly recommending **against** that approach: https://stackoverflow.com/a/48111781/174843 – Vince Bowdren Jul 26 '18 at 12:26
  • I used exactly your answer to set my project. It worked great! – Bruno Ornelas Jul 26 '18 at 13:22
  • Thanks Bruno Ornelas; as that other question and answer were a perfect match for you, I'm going to tag this question as a duplicate. Just so you know, that means that the questions will be linked, not that your question will be closed as such. – Vince Bowdren Jul 26 '18 at 13:57
  • Possible duplicate of [Unable to run mongo container with replica set using docker-compose](https://stackoverflow.com/questions/47674704/unable-to-run-mongo-container-with-replica-set-using-docker-compose) – Vince Bowdren Jul 26 '18 at 13:58

0 Answers0