I am running my mongod replica set instances on docker with ssl/tsl security enabled.
I can connect from mongo sheel and mongocxx on the machine where my docker is running using below connection string.
mongo --ssl --sslCAFile /etc/mongodb/ssl/mongoCA.crt --host rs0/mongo1:27017,mongo2:27017,mongo3:27017 --sslPEMKeyFile /etc/mongodb/ssl/mongo_client.pem
the problem is I couldn’t connect to mongod running on docker from anothe machine.
Both of my machines are on same network.
I tried to bind_ip to 0.0.0.0 in my docker file but didn’t work for me.
I also tried this link from mongodb for configuring firewall but still I couldn’t establish connection from my remote machine.
does any one what am i doing wrong?
Below is my docker file
version: '3'
networks:
netBackEnd:
ipam:
driver: default
config:
- subnet: 192.168.0.0/24
services:
api:
hostname: api
build: .
ports:
- 8000:8000
- 8001:8001
- 8500:8500
depends_on:
- mongo1
- mongo2
- mongo3
volumes:
- "/etc/mongodb/ssl/client_ip.pem:/data/client_ip.pem:ro"
- "/etc/mongodb/ssl/mongoCA.crt:/data/mongoCA.crt:ro"
networks:
netBackEnd:
mongo1:
hostname: mongo1
container_name: mongo1
image: mongo:4.2-bionic
expose:
- 27017
ports:
- 27011:27017
restart: always
volumes:
- "/etc/mongodb/ssl/mongo1.pem:/data/mongo1.pem:ro"
- "/etc/mongodb/ssl/mongoCA.crt:/data/mongoCA.crt:ro"
- "/usr/local/mongo-volume1:/data/db"
entrypoint: ['/usr/bin/mongod', '--replSet', 'rs0', '--sslMode', 'requireSSL', '--clusterAuthMode', 'x509', '--sslClusterFile', '/data/mongo1.pem', '--sslPEMKeyFile', '/data/mongo1.pem', '--sslCAFile', '/data/mongoCA.crt', '--bind_ip', '0.0.0.0']
networks:
netBackEnd:
ipv4_address: 192.168.0.2
mongo2:
hostname: mongo2
container_name: mongo2
image: mongo:4.2-bionic
expose:
- 27017
ports:
- 27012:27017
restart: always
volumes:
- "/etc/mongodb/ssl/mongo2.pem:/data/mongo2.pem:ro"
- "/etc/mongodb/ssl/mongoCA.crt:/data/mongoCA.crt:ro"
- "/usr/local/mongo-volume2:/data/db"
entrypoint: ['/usr/bin/mongod', '--replSet', 'rs0', '--sslMode', 'requireSSL', '--clusterAuthMode', 'x509', '--sslClusterFile', '/data/mongo2.pem', '--sslPEMKeyFile', '/data/mongo2.pem', '--sslCAFile', '/data/mongoCA.crt', '--bind_ip', '0.0.0.0']
networks:
netBackEnd:
ipv4_address: 192.168.0.3
mongo3:
hostname: mongo3
container_name: mongo3
image: mongo:4.2-bionic
expose:
- 27017
ports:
- 27013:27017
restart: always
volumes:
- "/etc/mongodb/ssl/mongo3.pem:/data/mongo3.pem:ro"
- "/etc/mongodb/ssl/mongoCA.crt:/data/mongoCA.crt:ro"
- "/usr/local/mongo-volume3:/data/db"
entrypoint: ['/usr/bin/mongod', '--replSet', 'rs0', '--sslMode', 'requireSSL', '--clusterAuthMode', 'x509', '--sslClusterFile', '/data/mongo3.pem', '--sslPEMKeyFile', '/data/mongo3.pem', '--sslCAFile', '/data/mongoCA.crt', '--bind_ip', '0.0.0.0']
networks:
netBackEnd:
ipv4_address: 192.168.0.5
below is the docker ps output
37075e728a2f mongo:4.2-bionic "/usr/bin/mongod --r…" 2 hours ago Up About an hour 0.0.0.0:27012->27017/tcp mongo2
45a84da16c56 mongo:4.2-bionic "/usr/bin/mongod --r…" 2 hours ago Up About an hour 0.0.0.0:27011->27017/tcp mongo1
3615e7b08bf7 mongo:4.2-bionic "/usr/bin/mongod --r…" 2 hours ago Up About an hour 0.0.0.0:27013->27017/tcp mongo3
Thank you