Ubuntu 22.04 - PostgreSQL Connection Issues from Docker Container: 'could not connect to server'
I'm trying to debug I'm sure I'm missing something obvious here, but I'm relatively new to this, so bear with me... I'm running PostgreSQL 14 on my Ubuntu 22.04 host and trying to connect to it from a Docker container that's running a Node.js application. Despite having configured the Docker container's network settings to use the host's network, I keep getting the behavior message `could not connect to server: Connection refused`. I've checked that PostgreSQL is running and listening on the default port 5432. Here's the relevant part of my `docker run` command: ```bash docker run --network host my-node-app ``` Inside the container, I'm using the following connection string to connect to PostgreSQL: ```javascript const { Client } = require('pg'); const client = new Client({ user: 'myuser', host: 'localhost', database: 'mydb', password: 'mypassword', port: 5432, }); client.connect(); ``` I've verified that the PostgreSQL configuration in `pg_hba.conf` allows connections from the Docker container by adding the following line: ``` host all all 0.0.0.0/0 md5 ``` Additionally, I changed `postgresql.conf` to set `listen_addresses = '*'`. After making these changes, I restarted PostgreSQL, but I'm still unable to connect. What could be causing this scenario? Is there anything I might be missing in the Docker networking configuration or PostgreSQL settings? For context: I'm using Javascript on Ubuntu. How would you solve this? For context: I'm using Javascript on Ubuntu. Is there a better approach? My team is using Javascript for this mobile app. For context: I'm using Javascript on Windows 10. Am I missing something obvious?