"penis," 1610s, but certainly older and suggested in word-play from at least 15c.; also compare pillicock "penis," attested from early 14c. (as pilkoc, found in an Anglo-Irish manuscript known as "The Kildare Lyrics," in a poem beginning "Elde makiþ me," complaining of the effects of old age: Y ne mai no more of loue done; Mi pilkoc pisseþ on mi schone), also attested from 12c. as a surname (Johanne Pilecoc, 1199: Hugonem Pillok, 1256; there is also an Agnes Pillock). Also compare Middle English fide-cok "penis" (late 15c.), from fid "a peg or plug."
The male of the domestic fowl (along with the bull) has been associated in many lands since ancient times with male vigor and especially the membrum virile, but the exact connection is not clear (the cock actually has no penis) unless it be his role as fertilizer of the domestic hens, and there may be some influence from cock (n.2) in the "tap" sense.
The slang word has led to an avoidance of cock in the literal sense via the euphemistic rooster. Murray, in the original OED entry (1893) called it "The current name among the people, but, pudoris causa, not admissible in polite speech or literature; in scientific language the Latin is used" (the Latin word is penis). Avoidance of it also may have helped haystack replace haycock and vane displace weather-cock. Louisa May Alcott's father, the reformer and educator Amos Bronson Alcott, was born Alcox, but changed his name.
Cock-teaser, cock-sucker emerge into print in 1891 in Farmer and Henley ("Slang and Its Analogues").