Long, long ago, nails were living, breathing creatures that inhabited the forests near human villages. They were said to be tricksters, these devilish nails, and they often went into crowded places so unsuspecting humans would step on them. Some even coated themselves in a magical ugly orange-brown substance that made humans tense up painfully and die when injected into them. Now, I do not know if any of you have stepped on any type of nail before--as in a fossil or model of one, of course, not a living nail, as live imps like that have not roamed the world for many, many centuries--but it is very painful. Doornails derived pleasure from the pain of humans, you see. That is why many villages hired doornail hunters to extinguish these foul demons, as people valued their feet and lives very dearly.
The doornail hunters, as they were called, used very specific tactics to take out these evil creatures. They would raid nail colonies wearing thick, heavy boots to keep their feet safe, and they would catch the troublemakers using a special net. Upon returning to their homes in the villages, the hunters would force the weakened (if not already dead) nails into the doors of the townspeople with a hammer. This served as a morbid message to the surviving nails: should they come anywhere near the village, they would be killed, and their corpses would be put up for display on someone human's door. Thus, these imps came to be called "doornails".
It is said that the doornails, unable to harm humans as they had before, eventually died out. People liked the look of their doors being studded with devil corpses, though, so people began making their own (not living) nails to adorn their passageways. Rumor has it that sometimes, these nails are possessed by the evil spirits of the past, to take revenge and stab people's feet once more... This, however, is nonsense. The imps are dead: as we would say, dead as a doornail.
This cliche conjures up the image of every opening scene to Charles Dickens's A Christmas Carol to me, since it's used all the time to describe Jacob Marley's, y'know, extreme deadness. Given that it's nearing the holiday season, it'll probably be heard a little more often, so hey, now's a better time than ever to rethink its entire meaning.
Some say that Shakespeare coined the phrase, and some say it was some other poet guy named Plowman who first said it. I dunno.