We use a pretty non-standard Discourse install
.
But I suppose you just need to expose the 5432 port from docker to the host.
And from there block external attack vectors. pg_hba.conf, ufw, iptables and so.
It really depends on your case, maybe crafting a plugin or submitting a core PR can even be easier.