Can't add replica set to PRIMARY node

whether docker or not, if members are not running on the same machine, you cannot use localhost on any of them.

there are 3 places you need to check. /etc/hosts to give each member’s host machine a name in other members’ host machine, config file (usually /etc/mongo.conf) for net.binIp to allow from other members, and rs.add to add members with their respective IP addresses or DNS names (can be set in hosts file)

this is not required if you start all instances on a single host on different ports.