Dogs are highly territorial animals who feel a strong instinct to defend their territory. A dog will usually see its owner’s house and yard as its territory; also, when a dog is in a car, the car becomes part of its territory. Many dog attacks occur when a dog feels threatened on its territory. The Humane Society of the US’ recommendations for avoiding dog attacks include:

If a dog approaches you and you believe that it may attack:
Your intention at this point is to is to allow the dog check you out, and hopefully, decide that you’re harmless. Once the dog loses interest in you, slowly back away until he is out of sight.
If the dog does attack, put anything you have with you—your bicycle, jacket, gloves, backpack, purse, cane, or anything else between yourself and the dog. If you fall or the dog knocks you to the ground, curl into a ball with your hands over your ears and remain motionless. Try not to scream or roll around. You want the dog to lose interest in you.
Never try to separate dogs that are fighting.
It’s especially important to teach young children to behave safely around dogs. All the safety tips listed above can be taught to young children. They can also learn that dogs can startle easily, and that they should talk softly and move slowly around a dog. They should be shown the safe way to approach a dog, slowly, making sure the dog sees them, offering an outstretched hand for the dog to smell. Children can learn that they should never tease or chase a dog they know, and that they should avoid dogs they don't know.

The Humane Society offers this advice to parents about teaching children to read dogs’ body language: understand dogs' body language is another important way to avoid being bitten. Teach children that animals use body language to tell us how they feel, and that paying attention to a dog’s body language can help prevent a bite. An angry dog or one who is scared is more likely to bite, and should be avoided. Here are the signs to look for:
The American Veterinary Medical Association advises parents to start early in teaching children about safe behavior with dogs. Even toddlers need to know not to approach strange dogs, and to treat their own dog with respect and kindness. Because children are the most frequent victims of dog bites, parents and caregivers should never leave a baby or small child alone with a dog.