Unable to connect to the database error on all containers

After updating my stack to the latest, I'm starting to get this same error in all containers that are not the databases:
[Nest] 1 - 01/30/2023, 8:29:01 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (2)...
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
[Nest] 1 - 01/30/2023, 8:29:04 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (3)...
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
[Nest] 1 - 01/30/2023, 8:29:07 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (4)...
Error: connect ECONNREFUSED 127.0.0.1:5432
[Nest] 1 - 01/30/2023, 8:29:01 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (2)...
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
[Nest] 1 - 01/30/2023, 8:29:04 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (3)...
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
[Nest] 1 - 01/30/2023, 8:29:07 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (4)...
Error: connect ECONNREFUSED 127.0.0.1:5432
` However, all the containers are on the same network, and the container databases are just fine, ready to accept connections. Did something in the way the containers reach the database have changed? I don't understand why they are trying to go through localhost rather than using the container name.
1 Reply
danielo515
danielo515OP3y ago
I fixed it by adding more env variables to the .env file, specifically those about the databases hostnames:
DB_HOSTNAME=immich_postgres
REDIS_HOSTNAME=immich_redis
DB_HOSTNAME=immich_postgres
REDIS_HOSTNAME=immich_redis
This should be considered a breaking change, because previously they were optional, but now they are mandatory, and without them the server will not start, and will fallback to localhost, which will only work on the development environment However, nothing is stated on the changelog Please consider mentioning this

Did you find this page helpful?