使用码头和无花果设置mongodb复制集的正确方法是什么? [英] What is the proper way of setting a mongodb replica set using docker and fig?

查看:152
本文介绍了使用码头和无花果设置mongodb复制集的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图追随官方的 mongodb教程创建一个 fig.yml 文件与一些副本集,但总是被阻止如何调用 rs.initiate() rs.add(<主机名>< ;:port>)正确。



我发现这个SO答案解释为什么我不能从 shell ,而不调用 rs.initiate(),那么该怎么做呢?



哦,我正在使用 mongo:latest (v2.6.5)作为基本图像,无需任何修改。

解决方案

我有一个类似的问题,这就是我做的。我使用docker-compose而不是fig。



在我的docker-compose。

  mongors:
image:mongo
ports:
- 27017:27017
volumes:
- ./mongo:mongo
entrypoint:mongo / entrypoint.sh

在我的entrypoint.sh中:

 #!/ bin / bash 
mongod --port 27018 --replSet rs0 --fork --syslog --smallfiles
mongo --port 27018 --evalrs.initiate ({_id:'rs0',members:[{_i d:0,host:'localhost:27018'}]})
mongo --port 27018 --evalwhile(true){if(rs.status()。ok)break; sleep(1000) };

确保它可执行:

  chmod + x mongo / entrypoint.sh 

这有点黑客,但它有效:)


What is the proper way of setting a mongodb replica set using docker and fig?

I was trying to follow official mongodb tutorials to create a fig.yml file with some replica sets but always got blocked by how to call rs.initiate() and rs.add("<hostname><:port>") properly.

I found this SO answer explaining why I can't start everything just from the shell, without calling rs.initiate(), so how can I accomplish that?

Oh, and I am using mongo:latest (v2.6.5) as base image, without any modifications.

解决方案

I had a similar problem, this is what I did. I'm using docker-compose instead of fig.

In my docker-compose.

mongors:                                                                                                
  image: mongo                                                                                          
  ports:                                                                                                
    - "27017:27017"                                                                                     
  volumes:                                                                                              
   - ./mongo:mongo                                                                                      
  entrypoint: mongo/entrypoint.sh

In my entrypoint.sh:

#!/bin/bash
mongod --port 27018 --replSet rs0 --fork --syslog --smallfiles
mongo --port 27018 --eval "rs.initiate({_id : 'rs0', members : [{_id : 0, host : 'localhost:27018'}]})"
mongo --port 27018 --eval "while(true) {if (rs.status().ok) break;sleep(1000)};"

Make sure it's executable:

chmod +x mongo/entrypoint.sh

It's a little hacky, but it works :)

这篇关于使用码头和无花果设置mongodb复制集的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆