Stun guns are maybe a bridge too far. Plus you need to get up close to use one. I don't know how you are going to get a dog in a headlock, and I don't know why you'd want to give one the was already attached to you by its teeth an electric shock?
If you mean a taser, are you going to just whip it out and take a potshot whilst riding along, or are you going to dismount, adopt your firing pose and give a clear warning? Something along the lines of "Excuse me madam, you might be enjoying a relaxing walk but your dog has just wandered into the patch of my bicycle and as such must prepare to face the consequences" would probably do it.
In the spirit of the forum, you should probably cobble together a home made gun design with enough juice to bring down a rhino. Mount one to your helmet and one to your bars, preferably with some kind of DIY device bodged from old bike bits and zip ties. Patrol your local woods immolating small animals and taking pictures of the results.