The phrase has been used since at least as far back as the 1700s to mean a life of misery or one of total subservience to someone else. People weren't always as kind to dogs as we now tend - or at least claim - to be and they are of course utterly submissive to their masters.