Is it possible to connect to the database directly from a separate app?

The way I got this to work (from outside the container) is to use an SSH tunnel. I actually created a new user instead of using postgres and have custom ports for SSH and postgres, but this should work for your setup:

ssh -L 5432:localhost:5432 EXTERNAL_VPS_IP "psql -U postgres -d discourse -h localhost"

The EXTERNAL_VPS_IP is the IP address you use to connect to your remote server.

If it still doesn’t work, you might want to try changing the exposed IP in app.yml to use the docker bridge IP instead of the internal container IP you got from docker ps. I’m not sure if this is required, but it’s how I have it set up:

expose:
  - "127.0.0.1:5432:5432"
# or if you use a custom port:  - "127.0.0.1:CUSTOM_PORT:5432"

Remember to rebuild the container afterwards.

Let me know how this goes. It took me A LONG TIME to get everything working (and it was so simple in retrospect), so I’m happy to help out.