I want to connect to my mongodb running on my localhost machine (dockerhost) from inside a docker container. For that I have to allow connections other than localhost. Unfortunetly when using --bind_ip 172.17.0.X mongod wont start, as also mentioned here:

https://www.mongodb.com/community/forums/t/mongodb-assigning-docker-gateway-to-mongo-conf/188768

It works with bind_ip_all, but that exposes the API completly, which I dont want for obvious security issues. Does anyone know, how I can expose it localhost + docker only?

Thanks for your help

3 Replies 3

ACtually found the solution

  1. Start docker container with --add-host host.docker.internal:host-gateway

  2. connect via mongodb://host.docker.internal:27017 from inside docker container

Looks like you misunderstand the --bind_ip parameter. It means on which IP your MonogDB is listening. Using localhost or 127.0.0.1 (or actually every IP between 127.0.0.1 and 127.255.255.255) allows only connection from the local machine/container.

If you use --bind_ip 172.17.0.1 and 172.17.0.1 is the only IP of your machine (which is most likely the case) then --bind_ip localhost,172.17.0.1 and --bind_ip 0.0.0.0 or --bind_ip_all are basically all the same.

Using --bind_ip with an IP makes only sense on a machine with more than one network interface.

Apart from that, I recommend to enable authentication on every case - no exception!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.