EDIT: OK I've done some reading about cancer and evolution. Clearly there is an evolutionary process happening inside each person's body that "selects" for cancers that are good at their "job". However even the most successful of those have no hope of passing beyond their host unless they also mutate a transmission mechanism for themselves, which happens much less often (but the Internet tells me it has been known to happen in dogs).
Generally, infectious cancer is a result from a population that either regularly has open wound contact, and or is very closely related genetically.
Given enough time cancer can even start to survive on it's own: https://en.wikipedia.org/wiki/HeLa It's actually become somewhat difficult to avoid cross contaminating samples with this cell line.
Oncoviruses are another transmission vector. HPV, or human papillomavirus, is a virus that causes warts (of all kinds) in humans, and also causes several kinds of cancer, including cervical and esophageal cancers.
A third way would be a pretty rare thing in humans, but is thought to be behind some of the canine cancers you mentioned: direct transplantation of cells. The tasmanian devil is on the edge of extinction thanks to a facial cancer they get from each other through this mechanism.
See also epithelial to mesenchymal (ETM) transition, in which cells lose their anchors and become an entirely different kind of cell so that it can better infiltrate other parts of the body.
It's pernicious and highly specialized because that's why it survives. And that's why everyone will die of cancer if something else doesn't kill you first.