supercharge / mongodb-github-action

Use MongoDB in GitHub Actions
MIT License
222 stars 46 forks source link

How do I bind to all available interfaces? #52

Closed sellomkantjwa closed 4 months ago

sellomkantjwa commented 1 year ago

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

marcuspoehls commented 1 year ago

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

sellomkantjwa commented 1 year ago

@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