In this picture, something's clearly caught Lily's attention. (It's probably Nemo hiding behind a shrub - they like to play hide and seek.) This is called a distraction. The bane of a dog owner's existence, the distractions. They're everywhere! Another dog, visitors, a dead bird, a bouncing ball, the smell of a hamburger on the grill -- you don't have to go very far to run into a distraction.
The mistake some dog owners make is thinking that if their dog knows a behavior in class or at home, the dog knows the behavior. Wrong. The dog knows the behavior in that specific place under those specific circumstances. Add in some distractions and you've got a dog who can't do what you've asked. Not because he's willful or stubborn or hard headed. But because you're asking too much of him.
Work with distractions, not against them. That means using a distraction as a "teachable moment." If your dog really wants to greet the visitors, ask him to sit first to earn that privilege. If he sits, he gets to say hi. If not, he doesn't get to say hi. The important thing to remember when working with distractions is to keep them low enough that your dog is able to be successful. That's really important - we're looking for success, not looking for failure. So maybe if your dog is too riled up to greet guests at the front door, he's behind a baby gate for 15 or 20 minutes until everyone's settled (including your dog), and then you bring him on a leash to say hello to the visitors.
Distractions vary from dog to dog - what is irresistible to one dog, another dog barely notices. Your dog is in an individual - work with him and his preferences. Once he realizes that his behavior allows (or doesn't allow) him access to the things he loves, you'll be on your way to a well behaved dog!