How do I access a database on the host from a container?

Hello,

Some background info on why I would like to do this:
We want to make the deployment to our servers cleaner by deploying to a container and making an image of the container so it can be spun up where necessary. The problem is that each server has its own database that we need to use and also migrate as we do these deployments.

So, is there any way I could access a postgresql database on the host from a container?
If this is not good practice, please let me know how databases are usually handled in a production environment.
I did try to find articles and documentation about this, but couldn’t find anything answering my question.

You can do it over the network just as you would if they were two different systems.

Alternatively you could use LXD’s proxy device or even a bind-mount of the host’s postgres socket, but that approach may run into issues when/if the postgresql process is restarted on the host (the bind-mount would become invalid).

Thanks for the reply @stgraber, I’ll try that.