Cannot connect to local mongodb from containerized application on local

I am running local mongodb on Ubuntu, all latest. Connecting from a regular local application is fine. However when I am running a java application in docker container locally, the same app does not connect. Tried using host.docker.internal - this is not regognized. Tried to use actual local IP as or docker specific local IP as both are recognised, however getting connection refused. Java exception is:
exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by { Connection refused}}
Is there any specific configuration in local mongodb that might prevent accepting this connection? I am assuming the port should not change from default being 27017


Is the mongodb instance configured to accept connections from your container’s IP address?

Share the command you used to start your docker instance.

Docker is started as daemon on Ubuntu. I would not know exact command, I believe it is as default as possible.


I did not realize local docker has its own IP address, thanks for the hint. Figured out it is
However I am now not sure where the heck local mongodb has its configuration. Mongo is very much quiet about anything that is not Atlas - any queries in google give everything about Atlas but almost no documentation about local deployment. So where is that configuration for local?


make sure that firewall and antivirus do not block the MongoDB connection on port 27017.

The location of the configuration file would depend on the operating system and how you installed MongoDB: