It is not unknown for a dog to use a fear reaction as an attention-getter. If a puppy learns that barking at an object, any object, will result in his owner giving him all sorts of comforting attention, he will very quickly realize that if he wants attention, he should bark, and preferably in an alarmed fashion so he can get instant response from his owner or anyone else around.
Method 1. Wait till he quietens down.
Some puppies don't bark very much, others bark a lot .The main way to control barking in dog training is to wait until the pup has quietened down before giving him what he
wants.
Excess barking when he wants out, can be controlled by getting him to sit quietly before you open the door. Of course, he has a right to tell you he needs out, but once he has told you; he does not have to repeat the message.
Barking at visitors can be stopped by good dog training by ensuring they only give your dog attention when he is quiet. You can also improve him by teaching him how to greet visitors nicely.
When he barks in alarm it is an attempt to give you information about goings on he thinks you should be aware of, so saying good dog helps in getting him to be quiet because you have told him you got the message, so he does not have to repeat himself.
Method 2. Use whispering
Do note that whispering tends to be more effective dog training for quietening a barking dog than shouting at him. You can also to teach pups to bark on your command, by rewarding them, with a command word, after which you can easily get them to be quiet.
The most important thing for you to do is to be able to control your pup when you need to, for example at night when people are sleeping.
Method 3.
Exercise him first
Normally you will want your puppy to be quiet while you are out, and not to disturb the neighbors. In that case he's more likely to fall asleep if you have taken him for a walk, or had some form of external activity with him before you go out.
Smaller puppies should not go on very long walks, just enough time outside to let him do his business. Try to get someone to come in and walk him when you are out for a long while. This helps break up his day, so he spends more time sleeping, and he doesn't get bored. Puppies often bark when bored.