replica Set mongo docker-compose

前端 未结 4 1866
长情又很酷
长情又很酷 2020-12-25 13:44

I\'m trying to configure a mongodb replicaSet using docker-compose, but when I stop the master container it seems that it doesn\'t pass to the secondary.

red         


        
4条回答
  •  隐瞒了意图╮
    2020-12-25 14:19

    Update: This does not work! You do need to run rs.initiate()

    With MongoDB 4.0, you don't need a 4th container to run a setup script. It is really simple to bring up a replicaSet of 3 containers:

    version: "3"
    services:
      mongo1:
        hostname: mongo1
        container_name: localmongo1
        image: mongo:4.0-xenial
        expose:
          - 27017
        restart: always
        entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
      mongo2:
        hostname: mongo2
        container_name: localmongo2
        image: mongo:4.0-xenial
        expose:
          - 27017
        restart: always
        entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
      mongo3:
        hostname: mongo3
        container_name: localmongo3
        image: mongo:4.0-xenial
        expose:
          - 27017
        restart: always
        entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]
    

    More info here: https://github.com/msound/localmongo/tree/4.0

提交回复
热议问题