Created
September 14, 2018 19:00
-
-
Save asoorm/7822cc742831639c93affd734e97ce4f to your computer and use it in GitHub Desktop.
Mongo Replica Set docker compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
mongo1: | |
hostname: mongo1 | |
container_name: localmongo1 | |
image: mongo:4.0-xenial | |
expose: | |
- 27017 | |
ports: | |
- 27011: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 | |
ports: | |
- 27012: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 | |
ports: | |
- 27013:27017 | |
restart: always | |
entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ] |
docker exec -it mongodb /bin/bash
This worked perfectly for me to create and start the mongodb set on docker containers. I can also connect to any of the servers using compass. But when I tried to open a connection from another server in the docker network (a php server), using php mongodb client, I got "Authentication failed" using this url:
mongodb://172.24.0.5:27017,172.24.0.3:27017,172.24.0.4:27017?replicaSet=dbrs
I am also sending my username and password, same that I am using in the compass connection url. The internal ips are correct, so that is not the problem.
So, basically, replicaset is up and running, I can connect from MongoDB Compass but I can't connect from my PHP code from a docker container in the same docker network.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By the way, you all would have to expose all Mongo replicaset instances ports in order to get connected to them, so I think It's redundant being exposing ports, It's better to use host network mode.
I was looking for a simple Compose for this and, unfortunately, I didn't find one complete and simple at the same time, because of that I made one as simple as possible where the secondary ones ingress their selfies on the master without any third-party script.
I hope you all find it useful