By behaving altruistically, would be the most common answer and by sacrificing one's interests in favour of one's friends.
Friendship implies the converse of egoism, both psychologically and ethically.
After all, it is characterized by unconditional love, by unselfish behaviour, by sacrifice, when necessary. On the one hand, the dog's friendship seems to be unaffected by long term calculations of personal benefit. But that is not to say that it is not affected by calculations of a short-term nature. The owner, after all, looks after the dog and is the source of its subsistence and security. Thus, the first condition, seemingly not satisfied by canine attachment is that it be reasonably unselfish.