mongodb-github-action icon indicating copy to clipboard operation
mongodb-github-action copied to clipboard

How do I bind to all available interfaces?

Open sellomkantjwa opened this issue 2 years ago • 2 comments

Thank you for all the good work on this, highly appreciated 🙏🏾

My use case is to connect to the replica set from inside a service container . I can't use localhost because otherwise the service container will try to connect to itself. So I tried using the docker gateway address (172.17.0.1). On this address I get ECONNREFUSED, presumably because the replica set is not listening on that interface. Is there a way to listen on all available interfaces? Or is there a better way to connect from a service container?

Thanks, Sello

sellomkantjwa avatar Aug 16 '23 18:08 sellomkantjwa

@sellomkantjwa Hey Sello, did you find a solution for it already?

marcuspoehls avatar Aug 26 '23 13:08 marcuspoehls

@marcuspoehls I ended up running my replica set manually. I used these 2 steps to set up a single node replica set:

  - name: Start mongo
    run:  docker run -d -p 27017:27017 --name mongo  mongo:6.0 --replSet test-rs --bind_ip_all

  - name: Initialize MongoDB Replica Set
    run: |
      sleep 10
      docker run --rm mongo:6.0 mongosh --host 172.17.0.1 --eval 'rs.initiate({_id: "test-rs", members: [{_id: 0, host: "172.17.0.1:27017"}]})'

Then, from your service container, you can connect using the address 172.17.0.1:27017

sellomkantjwa avatar Aug 26 '23 18:08 sellomkantjwa