Exercising outdoors — or even just walking somewhere — can have risks, and almost every runner has at least one story (usually many more) about being chased by a dog.
I have noticed that people whose off-leash dogs chase and jump up onto strangers are often very quick to say “Oh he’s just friendly!” This is probably true — at home and with people the dog knows well. But even a well-behaved, well-trained dog can get spooked by something and have a hostile or dangerous reaction.
I wish I had a good solution for this, but the best thing we can do to protect ourselves is to be aware of dogs around us, especially if they are off leash, and try to avoid them. In some cases, this may mean going out of your way to put distance between you and the dog, but that’s always going to be more convenient than dealing with a dog bite.
Strangers can be inappropriate with dogs, too — often approaching and touching dogs who are tied up on the sidewalk or reaching out to attended dogs without asking permission. You should give a dog plenty of personal (canine?) space, ask permission before touching a dog, and assume that if no one is there to give that permission that you should not touch the dog.
When I pass someone with a dog, and that person pauses momentarily to leash their dog or simply to call the (leashed) dog’s attention, I make a point of thanking them with a smile. It’s the sign of a good dog owner and a good neighbor. And most dogs would rather interact with their owners than a stranger, anyway!