Replication set conect to mongo express

Hello, im devoloping a replica set mongo db with docker.
----->docker-compose:

version: “3”

services:

mongodb1:

hostname: mongodb1

container_name: mongodb1

image: mongo:5.0

networks:

  - replica-docker

expose:

  - 27017

restart: always

entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]

mongodb2:

hostname: mongodb2

container_name: mongodb2

image: mongo:5.0

networks:

  - replica-docker

expose:

  - 27017

restart: always

entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]

mongodb3:

hostname: mongodb3

container_name: mongodb3

networks:

  - replica-docker

image: mongo:5.0

expose:

  - 27017

restart: always

entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ]

mongosetup:

image: mongo:5.0

networks:

  - replica-docker

depends_on:

  - mongodb1

  - mongodb2

  - mongodb3

volumes:

  - .:/scripts

restart: "no"

entrypoint: [ "bash", "/scripts/mongo_setup.sh"]

mongo-express:

image: mongo-express:latest

depends_on:

  - "mongodb1"

  - "mongosetup"

networks:

  - replica-docker

environment:

  - ME_CONFIG_MONGODB_SERVER=mongodb1

ports:

  - "8081:8081"

restart: alway

networks:
replica-docker:

---->this is my mongo_setup.sh:

#!/bin/bash

echo “sleeping for 10 seconds”

sleep 10

echo mongo_setup.sh time now: date +"%T"

mongo --host mongodb1:27017 <<EOF

var cfg = {

"_id": "rs0",

"version": 1,

"members": [

  {

    "_id": 0,

    "host": "mongodb1:27017",

    "priority": 2

  },

  {

    "_id": 1,

    "host": "mongodb2:27017",

    "priority": 0

  },

  {

    "_id": 2,

    "host": "mongodb3:27017",

    "priority": 0

  }

]

};

rs.initiate(cfg);

EOF

—>But i dont know why , my mongoexpress its not conecting to my replica set, it dosent show any error, but when i go to the browser (localhost:8081) it shows that its not working.Can you guys help me please

Hi @Alexandre_Sousa,

Can you connect to the RS using mongosh and share the result of rs.status()?
Can you share the connection string you are using? What does it looks like?
We agree that these 4 machines are all on 4 different physical machines, correct?

Cheers,
Maxime.