A Cockney used to be defined as someone ‘born within the sound of Bow Bells’ in the City of London, but this is no longer a residential area so it is now a general term for someone born in the East End of London. At the end of the Industrial Revolution in the 1840s the City was crowded with office blocks, warehouses, marketplaces and traders. Inevitably, communities formed and found ways to delineate themselves. Out of this came Cockney rhyming slang ~ a code designed to avoid saying the actual words you mean ~ particularly useful for in-jokes, fooling outsiders (including policemen) and tribal bonding.
Words chosen to be coded were mainly body parts, money, clothes, states of being and rude words. There were two main types of code. Both involve having a phrase which rhymes with the target word, e.g. Barnet fair -> hair. The first method would then drop all but the first word of the phrase ~ so, Barnet means hair. The second method simply keeps the whole phrase, e.g. trouble and strife -> wife. Some of these codes have entered the main language and are well-known around the country, e.g. “Let’s have a butcher’s” means “Let’s have a look” (butcher’s hook).
(Top image: Cory Doctorow at Flickr.com / CC BY-SA 2.0)