Docker Community Forums

Share and learn in the Docker community.

Configure Remote Access for MongoDB replica set runnng on docker container on Ubuntu 18.04

So, I am running my mongod replica set instances on docker with ssl/tsl security enabled. Everything is working fine when connect from same host where the docker is running.

I am trying to connect from the another computer to the mongod running on docker.

I have tried changing bind_ip to 0.0.0.0 in my docker file and allowed the port mentioned in this article but didn’t work for me.

Below is my docker file.


version: '3'
networks:
    netBackEnd:
        ipam:
            driver: default
            config:
                 - subnet: 192.168.0.0/24
services:
    api:
        hostname: api
        volumes:
            - "/etc/mongodb/ssl/client_ip.pem:/data/client_ip.pem:ro"
            - "/etc/mongodb/ssl/mongoCA.crt:/data/mongoCA.crt:ro"
        build: .
        ports:
            - 8000:8000
            - 8001:8001
            - 8500:8500
        depends_on:
            - mongo1
            - mongo2
            - mongo3
    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.4

any idea what’s going wrong?