Typically it means that you woke up with a hang over because you drank too much alcohol last night. Someone stole your head and left an elephant there instead. You're hung over, you're hung. That's better than being hung out to dry or hanged by the neck. Who are you going to call, Ghost Busters? You're going to consume a hair of the dog that bit you the night before, like vaccine you're going to vaccinate yourself with something that will kill the infection, lower the fever, protect you against the dog that gave you the elephant head in the morning. You are going to drink more alcohol to kill the hang over. Just a little more alcohol, just a hair... of the dog that is alcohol. A hair means just a little. To win by a hair.
There is a further connotation which includes the word "vaccine". It comes from the word meaning "cow". The medicine came from cows? Yes! I was "vaccinated" against smallpox and polio.