Dogs have a long, proud history of scavenging. After all, living on the outskirts of human encampments and eating leftovers was how they first became "man's best friend." Teaching a dog to stay out of the garbage can be an uphill battle but luckily there are easy ways to deal with this.
Keep outside garbage cans securely away from your dog's reach. It can be very dangerous if your dog gets into a garbage can and eats cooked bones, since these can kill him. Dogs can get quite ill from eating certain leftovers, not to mention the other things they might eat, like aluminum foil. If a dog is left outside in a yard with nothing to do, it is simply too much to ask of him to ignore the tantalizing smells coming from an outside garbage can. Many people have to secure their garbage cans from strays and wild animals. There are garbage cans available with twist-locking lids that will deter a bear. Using one of these will ensure that no matter how hard he tries, your dog won't be able to get into the garbage.
If for some reason you are unable or unwilling to secure your garbage can (whether it is outside or in your home) from the dog, there are deterrent sprays available at pet stores, cayenne pepper and powders like bitter alum that are so unappetising your dog will think twice about trying it again. You will have to bait the can with something that smells good to your dog. Use your deterrent of choice. Leave the area and let him find out for himself how awful it is. For some dogs, deterrents like this work but they are not a guarantee. You still should be very careful about cooked bones and other things that will be dangerous to your dog.
Of course, most well mannered dogs will not try to get into the garbage in your presence. If your dog understands NO or AHH AHH or whatever word you use to tell him to stop doing whatever he is doing, this is all you need to tell him not to get into the trash when you are there. Just because he complies in your presence doesn't mean he'll be able to resist if you leave him alone with an attractive smelling garbage can though!