The origins of the word are in the combining of "cock", a male bird, and "ey", an old form of the modern word "egg". "Cocken" (of or having to do with cocks) + "ey" [i.e, "cocken|ey"] first appears in written English in the 14th Century. Originally it meant a small, badly shaped egg. In time it came to mean a spoiled or effeminate boy, then it was used by country people to describe a city dweller, who were felt to be effeminate and unmanly by comparison. Eventually it came to mean a resident of London itself.
In the City of London is a historic church, called St. Mary-le-Bow. To be a real Cockney, a person must be born within earshot of Bow Bells, the colloquial name for the bells of the church tower.