“Even the cuddliest, fuzziest,sweetest pup can bite if provoked. Most people are bitten by their own dog or one they know. Some owners actually promote aggression in their dogs or allow aggression to go unchecked. Although media reports and rumors often give the impression that certain breeds of dog are more likely to bite, there is little scientific evidence to support those claims,” American Veterinary Medical Association (AVMA) added.
I thought this was an excellent article:
Any Dog Can Bite. Here’s How You Can Prevent It | I'm Not a Monster
No, dogs do not bite “out of the blue.” There are always warning signs before a bite occurs, but these can be very subtle and may be missed by many people. A dog may appear to tolerate being repeatedly mauled by a child and one day bites, surprising everyone. Sometimes the warning have gone on for months or even years before the dog finally loses its tolerance and bites.
There is tons of information on it.
Also, here's an article I found on greeting dogs:
How To Politely Greet A Dog
Lots of dogs actually hate to be petted on the head, especially by strangers.