Best actions:
Face the dog. Do not run. These are interpreted by dogs as not being afraid (even if you are).
Raise a fist, as if you intend to throw something or swing at the dog. Dogs seem hard wired to interpret this as a threat, and most will back down simply from the motion alone. If you can grab a rock or something to throw first, do so.
You may not have to throw it.
Slowly back away facing the dog. If you can get out of its territory it may give up.
Yell "NO!" Some dogs may attack not recognizing you as human. Hearing a human voice may help bring them out of prey chasing mode. Some are trained to stop at no. Yelling no, or bad dog, may alert the owner.
If all these fail and the dog continues to attack, beware. Many dogs will not automatically bite, they will just rush up close to you threatening and snarling.
They like to bite arms and hands hanging down, so keep your hands up out of the way. Beware of kicking out with your foot. If you miss, it may be bitten.
Look for a weapon or something to climb up on (parked car).
You want to avoid physical contact. It this occurs you need to fight like hell and anything is fair game in self defense.
You need to worry about trained attack dogs, who will ignore all of the above and just head straight in. These are few and you are unlikely to encounter one.
This applies to bigger dogs that pose a real threat. You can be more aggressive with smaller dogs