You're walking your dog, and he is loosey-goosey, smelling the ground, taking in the scenery - until he sees another dog. Then bam, he's barking and lunging on a leash, catching you off guard.
Why does this happen, and how can you fix it?
Your dog may be reactive because he was never socialized as a puppy, because he was attacked by another dog, because he is protecting you, or because he thinks you won't protect him. The reason doesn't matter. What matters is that now you have to plan.
Having control of your dog outside starts with getting control and being prepared inside. During the day, do obedience exercises in the house and have him earn everything he wants by sitting - for his meals, petting, each throw of his ball. Everything. You're gaining control in familiar territory as well as gaining confidence yourself because he is now looking at you for direction in a nonthreatening environment, inside your house.
Go on several short walks rather than one long one. Bring at least 20 large, hard, meat-based treats with you - he has to chew them, not gulp them. Make sure they are easily accessible for you. A fanny pack is great to hold them.
Have him sit while you put on the leash and open the door. If he doesn't sit and stay seated until you release him, there is no walk. Walk away, take the leash with you, and ignore him for five minutes. Then try again. This first step may take several attempts before he realizes that he has to "pay" for the walk by sitting first.
As soon as you walk out the door, immediately take a treat out of your fanny pack and show it to him but don't give it to him. The treat needs to be in your hand during your walk.
The instant he sees another dog, stand between him and the other dog while at the same time moving out of the path of the other dog - into a yard, behind a mailbox or other large object, between parked cars, or even on the street side of parked cars if it's safe.
If he moves to your left in order to see the other dog, then you move to your left to block his line of sight. If he moves to the right, then you move to the right. It's very important that you control the space between the two dogs.
While you do this, give him the treat. As he chews the first treat, get out another treat so you can give it to him immediately after he finishes chewing. If he's chewing, he isn't barking, and you don't want to give him an opportunity to bark and lunge. Keep feeding him treats until the other dog passes.
Try to keep the leash loose. Don't talk to him or give him any cue/command except to tell him he is a good dog for chewing the treat.
Repeat this process every time you see another dog. The first several times, it's going to seem like there is no improvement in his behavior. And you're right. But what is happening is he's making a connection "when I see another dog, my person gives me a treat." Eventually (and it never seems to happen soon enough) when he sees another dog, he will automatically look to you for a treat. Honest. You'll probably faint. I almost did the first time it happened with my dogs.