Really this comes down to the docker networking namespace and being able to resolve the hostnames. It also relates to the replicaset discovery when a client connects, the hostnames and ports returned by db.hello() is what the client will try and connect to.
This would work if it wasn’t for docker. If you had multiple mongod on your local environment for example.
This is how I have have run a replset in docker and be able to connect from a local application.