I think there are two mistakes people make training a dog. Being too gentle or too harsh. Dogs don't understand sweet talk. A dog misbehaves and people try to comfort the dog and tell them how much they would prefer they didn't do that. Dogs really don't understand sentence structure. They most understand physical action and body language. When you pet the dog while you tell them how bad they are, what they get is the opposite instruction than you desire. Being harsh to the point of abuse trains the dog to be abusive or violent to others. When in a pack the leader does not say pretty please don't do that. Nor do they usually cause physical harm. It is more a matter of dominance or intimidation.
When I got my dog from the shelter she was what they call resource guarding. If she had something she liked and you got near, she would snarl. I addressed that by flipping her on her back putting a hand around her neck and I growled and snarled at her. Then let her up and we both stopped our aggression. It hasn't been an issue again. Dogs don't understand being disciplined for whatever happened 5 minutes ago. To them you just freaked out over nothing. You have to react quickly. Dogs live in the now. If the dog runs off and then comes back disiplining it for leaving doesn't work. all they know is they came to you and you freaked ot. better be real carefull coming to you.
Another thing she did was bark at people who were outside of the vehicle. I would pull into a shopping center and she would start. Anybody walking outside was something to bark at. Using stern NO's and a tug on her collar when she would bark at others cured that. She got the message that this was not acceptable and not her job to try to scare away parking lot intruders. Now she curls up and takes a nap when I leave her in the truck. We are both happier.
In most cases it isn't the dog that needs to be trained, but the owner. Many good books have been written. Cezar Millan would be a good start for a read. Your first job is not to be your dog's friend. You are it's pack leader. After that is established then you can be buddies.