The answer to this question is twofold:
1 – The ruling on keeping a dog.
It is haraam to keep a dog unless it is for the purposes for which Islam permits keeping dogs. Whoever keeps a dog – except a dog for hunting or farming – his reward will decrease each day by one or two qeeraats.
It was narrated that Ibn ‘Umar (may Allaah be pleased with him) said: “I heard the Messenger of Allaah (peace and blessings of Allaah be upon him) say: ‘Whoever keeps a dog, except a dog that is trained for hunting or a dog for herding livestock, his reward will decrease each day by two qeeraats.’” (Narrated by al-Bukhaari, 5059; Muslim, 2941; according to another version narrated by them both, “one qeeraat”).
The word qeeraat refers to a large amount of reward; if a person’s reward decreases by one qeeraat, that means that he is sinning, for losing reward is like earning sin, both indicate that something is haraam because of the consequences it leads to.
The impurity of dogs is the greatest of animal impurities. The impurity of a dog can only be removed by washing seven times, one of which should be with earth. Even pigs, which the Qur’aan states are haraam and describes as an abomination (rijs) are not naajis (impure) to such an extent.
Dogs are impure and filthy, but unfortunately we find that some people are attracted to the ways of the kuffaar and their filthy habits, so they have started to keep dogs unnecessarily for no reason, keeping them, training them and cleaning them even though they can never be clean, even if they were washed with the waters of the ocean, because they are essentially impure.
Our advice to them is to repent to Allaah and to get the dogs out of their homes.
But in the case of dogs which are needed for hunting, farming and herding livestock, there is nothing wrong with that because the Prophet (peace and blessings of Allaah be upon him) gave permission for that. If you throw this dog out of your house, you will no longer be responsible for it, so do not keep it with you.
2 – The ruling on touching a dog
If you touch it when it is not wet, then your hand does not become impure, but if you touch it when it is wet, this means that the hand becomes impure, according to the opinion of many scholars, and the hand must be washed seven times, one of which should be with earth.
With regard to vessels, if a dog has licked a vessel (i.e., drunk from it), then the vessel must be washed seven times, one of which should be with earth, as was proven in al-Saheehayn and elsewhere, in the hadeeth narrated from Abu Hurayrah (may Allaah be pleased with him) who said that the Prophet (peace and blessings of Allaah be upon him) said: “If a dog licks the vessel of any one of you, let him wash it seven times, one of which should be with earth.” It is better if the washing with earth be the first washing. And Allaah knows best.
See Majmoo’ Fataawa al-Shaykh Muhammad ibn ‘Uthaymeen, 11/246; Fataawa Islamiyyah, 4/447.