it comes from an old Greek fable about a dog who was sleeping in a manger on straw. An ass came into the manager to eat some straw, the dog bites the ass, despite the fact that the stray is no use to the dog. (for being edible at least). so the logic is the dog bite the ass out of spite.
you are in a shop and want to buy a bottle of water, the shop only has a large bottle (very large). Much more than you can drink or carry. Rather than take a little water and allow someone else to have some water, you empty the water down the drain. you are being "dog in the mangerish"