Issue with mongo replica

Hello everyone,
I have a Mongo setup of three nodes (Primary, Secondary and Arbitrary) both Primary and Secondary have the same priority and when secondary goes down i can keep connect to the RS but when the primary goes down and the secondary becomes primary i can’t connect to the RS as it gives (connect ECONNREFUSED 127.0.0.1:27017)

at that moment a direct connection to the secondary works fine!

I am running the RS locally on docker and my connection string is :

mongodb://admin:admin@mongo-rs1:27017,mongo-rs2:27018/admin?authMechanism=SCRAM-SHA-1&replicaSet=rs0&readPreference=primaryPreferred