Postgres DB configuration issue

Postgres is hosted on localhot and port 5432

TL;DR: Try using host.docker.internal (if you are running Docker on Mac or Windows)

More details…

localhost is always relative to the system you’re running it in. When farmOS is in Docker, then localhost essentially means “the same system as farmOS” - but that’s not where the database is installed.

It sounds like you have the database installed on the host system (alongside the Docker container that farmOS is running in). From the perspective of the host system, the database is on localhost, but from the perspective of farmOS (running in Docker), the database is NOT running on localhost, it’s running on the host system, which will have an IP address set by Docker.

The reason we don’t include a database service in the production docker-compose.yml template is because we leave it up to the administrator to decide where they want to host the database. Running it in Docker, like the development template does, make it easy to reference the database host because Docker will make the service name (db) available as a hostname in all the Docker services. Running it on a separate server is also easy, because you can reference that server’s public hostname. Running it on the host server while farmOS is in Docker is tricky because you need to figure out what IP address Docker assigned to the host.

This StackOverflow question might be useful: How to get the IP address of the docker host from inside a docker container - Stack Overflow

If you are running on Mac/Windows, this is actually pretty easy. Just use host.docker.internal.

Linux doesn’t have a handy shortcut like that, unfortunately.

Hope that helps!

3 Likes