Just like people.
Jean Donaldson has many choice words in her book Culture Clash for people who endow their dogs with saintlike virtue, then bust them down to felon status when they misbehave. One of the greatest barriers to effective and positive training is the myth that dogs live to please us. Like all living things, they live to please themselves; they just happen to be more directly dependent than most on the whims of an alien and unpredictable species. Yes, they (or their ancestors) chose this fate for themselves (by degrees, over millennia); because humans are fickle and more powerful than wise, many animals have found that their best (or only) hope for survival lies in making themselves indispensable to us. Plants, too-- Michael Pollan's book The Botany of Desire offers four wonderful case studies of species that have piggybacked on the naked ape and thereby turned our unseemly success into their own.
Our long shared history with dogs does complicate the equation some. Many evolutionary biologists are less biased than they once were in the direction of Hobbesian viciousness (yes, it's hard to drop the moral vocabulary here); they begin to credit and elucidate the ways that humans and other social species find selfless behavior paradoxically rewarding. The phenomena of empathy and altruism do not contradict the tenets of Darwinian selection, but they do tangle them up rather beautifully. We have very good reasons, reasons articulated in creed and law but encoded in our DNA, to show consideration to others and selectively curb our "animal" appetites.
The spontaneous pleasure we often take from our own acts of kindness speaks to the adaptive value of generosity: it wouldn't feel so good if it didn't boost our chances in the genetic wheel of fortune. Sarah Blaffer Hrdy has written a brilliant, persuasive, and finally dismaying account of how the human capacity for connection might have become so well-developed under one set of evolutionary pressures, and how it might just as naturally fall apart as those pressures shift. Mothers and Others: The Evolutionary Origins of Mutual Understanding is the most compelling and nuanced synthesis of biology and anthropology I've yet read.
If dogs' ancestors were not already highly social, if they hadn't already evolved to take pleasure in the company of their fellows well before they got on the human gravy train, it's doubtful that we would ever have become so symbiotically enmeshed. As it is, dogs and humans have kept company for more than ten thousand years. In spite of our many differences and misunderstandings, both species have found it "good" to care, and extended our capacity to care across a great genetic gulf. It's not magical, but it is marvelous.