mongodbcontainersworkflowapache-nifipodman

NiFi in podman connection refused with GetMongo when using mongodb://localhost:27017/ hosted in local machine


I have a MongoDB server hosted and running in my local machine using port 27017 and I want to create a simple workflow in NiFi which copies the details from a collection to a directory using GetMongo and PutFile. My NiFi is hosted in my podman using port 8443 this is the script:

podman run --name nifi --cap-add=NET_RAW -p 8443:8443 --network host -e SINGLE_USER_CREDENTIALS_USERNAME=admin -e SINGLE_USER_CREDENTIALS_PASSWORD=admin -e NIFI_WEB_HTTPS_HOST=0.0.0.0 -e NIFI_WEB_PROXY_HOST=localhost:8443 -v "D:\userPath\Programs\mysql-connector-j-8.3.0:/opt/nifi/jdbc-drivers" -d apache/nifi:latest

As seen in the details, I have used --network host in my script so the podman can use the local machine's network for localhost and not its own in the container. I have also set up the MongoDB's configuration file from C:\Program Files\MongoDB\Server\7.0\bin to allow all connections with bindIp: 0.0.0.0. Additionally, I have allowed both ports 27017 and 8443 using netsh advfirewall firewall add rule name="Open Port [port]" dir=in action=allow protocol=TCP localport=[port] yet despite all of these, I'm still getting the following error:

06:10:19 UTCERROR97511fb5-0191-1000-986a-5829d4e6650c GetMongo[id=97511fb5-0191-1000-986a-5829d4e6650c] Processing halted: yielding [1 sec]: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]

Lastly, when I try this command netstat -an | findstr 27017 I got this result:

TCP 0.0.0.0:27017 0.0.0.0:0 LISTENING

So I know that MongoDB is indeed running and listening to port 27017

Did I miss anything during the setup? I'm new to both MongoDB and NiFi and wanted to try a simple setup yet I'm already stuck here, any answer is appreciated.


Solution

  • Turns out I made a mistake with the NiFi configuration. I was using the virtual IPv4 address instead of the assigned IPv4 in my local machine, and as I said above, because I used --network host in my podman run script it used the local machine's network.

    I first set a simple workflow of GetMongo process then I set Mongo URI to mongodb://192.168.*.*:27017/,

    Then I set bindIp in my mongod.cfg to my IPv4 address (192.168.*.*) and now the workflow works.

    Oops!