Cannot connect to replica set via mongo compass

This is not what I proposed. The replica set is not configured as as localhost. So you are specifying the wrong host. From the link you supplied the replica set is:

docker exec -it mongo1 mongosh --eval "rs.initiate({
 _id: \"myReplicaSet\",
 members: [
   {_id: 0, host: \"mongo1\"},
   {_id: 1, host: \"mongo2\"},
   {_id: 2, host: \"mongo3\"}
 ]
})"

This is again not what I proposed. I mentioned

and

So you are mentioning the wrong ports.

As already mentioned you are specifying the wrong ports.

I have mentioned that your replica set, if configured like the link you shared is configured with

So with 127.0.0.1 you are mentioning the wrong hosts.

The conclusion is that you have tried many things. The one thing you have not tried is the one I have mentioned:

Since you have tried many things except the one I shared I am not too sure that you

because you do not follow the only suggestion I offer. Please share the output of

docker ps 
and
docker exec -it mongo1 mongosh --eval "rs.status()"

Hopefully, they match what is documented in the link you shared.

Share the screenshot of the connection string that generated the Compass error