Docker + Kubernetes are the biggest socially-acceptable hacks in the industry at the moment.
In my opinion, they nicely abstract over server hardware and services running on them, so one is able to have simple infrastructure-as-code management of otherwise complicated setups.
It doesn't even make sense to connect to a managed database using 'localhost'.
Managed databases are never localhost. They are hosted outside your VPS and you use a DNS name to connect to them.
It does make sense to connect to localhost on dev machines. But if that's the setup, I guess one should avoid from tunneling to localhost to avoid potentially dangerous confusion (hmm... I think I'm guilty of that on a couple projects, need to check if that's true...)
Plus of course using git with a hook specifically for preview versus production (i.e. "git push production") that way local specific scripts can be stripped even if in same repo.