I haven't found any solutions to permanently lock the Dock to a single screen in macOS. But you can set the autohide-delay
user defaults to a larger value which also affects the time it takes for the Dock to move screens.
Command:
defaults write com.apple.dock autohide-delay -float 9999999
The value is in seconds. I've set mine to 5 seconds so I can always move it intentionally if I want to, but this gets rid of the unintentional moves.
It's also worth noting that this value seems to be ignored by the OS in some configurations. I've noticed the behavior is slightly different e.g. when you have screens arranged in a vertical setup on top of each other.
Found originally in this Reddit comment.