Dogs don't want to fight, they know that potentially it can be dangerous for them too. Most dogs demonstrate 5 survival strategies when confronted to a situation they are not comfortable with: Flight, Flirt, Freeze, Flock and (generally as a last resort) Fight. The Five Fs. Think about it, us humans sometimes uses these too.
Before any signs of aggression appear, a dog will have shown physical signs of stress, such as barking, panting, lip licking, lunging, hiding behind you or even jumping up at you. There are many more, but if we miss-read them, ignore them, or sometimes worse, suppress them through violent training towards the dog, they will have to act using one of the five Fs. And if the dog feels trapped, when on the lead maybe, or cornered, then his only option will be to fight.
Only very few dogs use aggression as a first strategy, and if they do, it's often because their past "aggressive" behaviour was rewarded or reinforced; maybe by their owners, maybe because the other scary dog or human "flew away", or just perhaps the simple fact that they survived that scary encounter. This could also be a strong reinforcer.
And who really suffers from these attacks? The humans, or the thousands of dogs who get killed every year because they demonstrated "aggressive" behaviour, or because "their breed has a tendency for these aggressive behaviours". Take care, and take time to get to understand your dog better, make sure you are aware of his body language and what he is trying to tell you.