The core source for the rainbow blessing is Berakhot 59a:12, where Rabbi Yehoshua ben Levi teaches that one who sees a rainbow must fall on his face, deriving from Yechezkel 1:28 that the rainbow's colors resemble the vision of God's glory, and that in Bavel the practice is rather to recite a brachah beginning 'Zocher HaBrit' rather than literally prostrating, since prostrating might appear as bowing to the rainbow itself.
This brachah is rooted in the covenantal sign described in Bereishit 9:13-15, where the rainbow is given as the token of God's covenant with Noach never to again destroy the world by flood, a point also drawn out by Midrash Tanchuma, Noach 6:1 and Pirkei DeRabbi Eliezer 23:13 in tracing the brachah's text to that covenant.
The halachic codifiers record this brachah in essentially identical language: Mishneh Torah, Blessings 10:16, Tur, Orach Chayim 229, Shulchan Arukh, Orach Chayim 229:1, Kitzur Shulchan Arukh 60:4, and Ben Ish Hai, Halachot 1st Year, Eikev 17 all give the wording 'Zocher HaBrit, ne'eman bivrito, vekayam be'ma'amaro.'
Alongside the brachah, the sources insist on a prohibition against staring at the rainbow at length. Chagigah 16a:11 and its parallel in Kiddushin 40a:18 teach that one who gazes at the rainbow shows disrespect for his Creator's honor, since the rainbow's appearance is compared in Yechezkel 1:28 to the vision of God's glory, and that staring at such things dims one's eyes. Shulchan Arukh, Orach Chayim 229:1, Tur, Orach Chayim 229, Kitzur Shulchan Arukh 60:4, and Arukh HaShulchan, Orach Chaim 229:1-3 codify this as forbidding only extended gazing, while Beit Yosef, Orach Chayim 229:1-2 explains, citing the Rosh, that mere seeing (ro'eh) is permitted while only intensified looking (mistakel) is forbidden, which is why one may look briefly enough to recite the brachah.
On the question of telling others, Mishnah Berurah 229:1-2 and its parallel formulation at Mishnah Berurah 229:1, citing the Chayei Adam, rule that it is not proper to tell one's friend that there is a rainbow, because doing so constitutes 'motzi dibah' — spreading a report that reflects badly, presumably on the generation's deserving punishment. Kaf HaChaim, Orach Chaim 229:1-8 cites this same ruling from the Chayei Adam and Peat HaShulchan in the name of the Petach HaDevir.
Against this, later authority disputes the point: Kitzur Shulchan Arukh Yalkut Yosef, Orach Chaim 229:1 rules explicitly that it is permitted to tell one's friend that there is a rainbow so that the friend too can recite the brachah, showing that the stringency recorded by the Mishnah Berurah is not universally accepted.
Related details about the brachah's recitation are also addressed among these sources: Mishnah Berurah 229:1-2 rules that if one sees the rainbow again, even within the same day, one repeats the brachah, since a given rainbow is likened to thunder in that it passes and is gone, unlike other brachot recited only once a month. Kitzur Shulchan Arukh Yalkut Yosef, Orach Chaim 229:2 adds that the brachah is said even if only part of the rainbow is seen, but not if seen through an obstruction or in a mirror, though seeing it through window glass or a car window remains valid, and Kitzur Shulchan Arukh Yalkut Yosef, Orach Chaim 59:28 rules that one who sees the rainbow during the breaks of Shema and its brachot should pause to recite it with Shem and Malchut since it is a passing mitzvah.