Just stop. Get off the bike. Leave the bike between you and the dog, unless you're being chased by a pack. Keep your shoulders and back straight, but tuck your head a bit down. That says to the dog you're letting him be the boss of the teritory, you're leaving, but you're not scared and will defend yourself.
If attacked by a pack, try looking the meanest, most eager dog to bite you in the eyes. Stay calm. 99% he'll back off. Have water bottle ready and spray him if he doesn't stand off in a second.
Most animals will not attack anyone without a good reason. If you make it clear to them you're leaving, not challenging them for teritorry, they will leave. 99% of the dogs are just annoyed by spinning of the pedals and feel happy to chase you. When you stop and dismount, they loose interest quickly.
Whatever you do, don't kick dogs while on the bike.