I've found that dogs aren't actually trying to attack, they just want to run with you. If I see a dog coming at me, I just ignore it and keep on riding the same way I was. The dog reaches me and just starts running along side me watching me ride for a while before it gets tired and goes away