I have a PostgreSQL 17.4 container running via Docker, and I can connect to it using psql, but my app server fails to connect.
docker version 27.5.1 docker desktop 4.38.0
these are the steps I took to debug the issue:
- Etc.hosts files - 127.0.0.1 resolves to localhost
- Check docker network type - seed_default - bridge
- I changed the daemon.json file to dns - my mac ip address
- Checked with docker run --rm busybox cat /etc/resolv.conf and the changes have been applied
- Checked docker run --rm --network=host busybox ping 127.0.0.1and connection is there, docker container reaches localhost
- running this docker exec -it seed-postgres-1 psql -U postgres -c “SHOW listen_addresses;” shows output * so Postgres is listening to all addresses
- Running this psql -h 127.0.0.1 -p 5432 -U postgres returns psql 17.2 postgres.app
- Running this docker exec -it seed-postgres-1 psql -U postgres -h localhost returns psql 17.4 Debian 17.4-1.pgdg120+2
- I stopped the postgres.app so it only connects to docker container
- Running psql -h 127.0.0.1 -p 5432 -U postgres it shows connection to server 17.4 (Debian 17.4-1.pgdg120+2))
- running docker exec -it seed-postgres-1 ss -tulnp | grep 5432 doesn’t return anything so postgres doesn’t connect to port 5432 ? (not sure)
- this docker inspect seed-postgres-1 | grep ‘“HostPort”’ outputs
-
"HostPort": "5432" "HostPort": "5432"
- I get access to my database via CLI but still the server does not start
the way I run the app is like this :
pnpm docker:db:down && pnpm docker:db:init
then pnpm dev
and I get error
Feb 27 01:09:08 error: [api] Error executing user/getUser: Error: getaddrinfo ENOTFOUND db.localtest.me
api:dev: at /Users/mioaracenusa/PersonalProjects/squared/node_modules/.pnpm/@neondatabase+serverless@0.10.4/node_modules/@neondatabase/serverless/index.js:1345:74
api:dev: at processTicksAndRejections (node:internal/process/task_queues:105:5)
api:dev: at async NeonPreparedQuery.execute (/Users/mioaracenusa/PersonalProjects/squared/node_modules/.pnpm/drizzle-orm@0.38.3_@neondatabase+serverless@0.10.4_@opentelemetry+api@1.9.0_@prisma+client@6._2ikk3wxp2xyn2wfim62gbnon7q/node_modules/src/neon-serverless/session.ts:102:18)
api:dev: at async UserService.getUser (/Users/mioaracenusa/PersonalProjects/squared/apps/api/src/services/users/user-service.ts:96:10)
api:dev: at async postHandler (/Users/mioaracenusa/PersonalProjects/squared/packages/rpc/src/index.ts:123:21)
web:dev: Error occurred during RPC request: RpcResponseError: getaddrinfo ENOTFOUND db.localtest.me
web:dev: at mapError (packages/rpc-client/src/index.ts:100:7)
web:dev: at UserService.doRequest (packages/rpc-client/src/index.ts:59:4)
web:dev: at async (apps/web/src/server/procedures.ts:51:14)
web:dev: at async Object.wrapperFunction [as handler] (apps/web/src/server/__internals/router.ts:53:17)
web:dev: at async Object.wrapperFunction [as handler] (apps/web/src/server/__internals/router.ts:56:5)
web:dev: 98 | }
web:dev: 99 |
web:dev: > 100 | throw new RpcResponseError(source, errResult, status);
web:dev: | ^
web:dev: 101 | }
web:dev: 102 |
web:dev: 103 | export class RpcResponseError extends Error { {
web:dev: code: ‘unknown_error’,
web:dev: type: ‘error’,
web:dev: source: [ ‘user/getUser’ ],
web:dev: status: 400
web:dev: }
at this point I’m clueless on what to check anymore!
I thought about network issues , something that might prevent the connection, but I don’t know…
I would appreciate any input .
if you require other info, I would be happy to provide.
thank you