Train. Train, train, train!!
My dog rings a bell when he wants to go out to pee, flops to the floor dead when I shoot my imaginary finger gun at him, will walk by my side among hundreds of people without a leash and never even thinking about roaming off, sits in his bed when the doorbell rings or somebody walks into our house and stays there until called upon to go see them. And best of all, he does not bark unless it's out of fear.
All of this because of how well my fiancé trained him. He does a crap load of other funny things and tricks we taught him too but the most important things are the obedient things like ringing the bell, not barking and not jumping/running at strangers/visitors.
Watch youtube videos. You can humanely train your dog to do anything. Key word, humanely.