Open SureshPradhana opened 3 months ago
Hi, can you confirm if the issue I reported is correct? If so, I'd like to work on it.
- The
.env
file is not being loaded, causing missing environment variables during runtime.- The
DATABASE_URL
useshost.docker.internal:35000
, which leads to connection errors within the Docker network.
Hi @SureshPradhana, thank you for your suggestion, and patience while we were out of office. Can you share the exact connection errors you experienced? They might be specific to your set-up. But we aim to support all environments, so it's important we learn what is going on here.
As for loading env vars, I agree they should be mounted to the volume / loaded at runtime, as you demonstrated. Our current set-up isn't best practice, this would be more secure and flexible.
Hi @kyleecodes,
Thanks for the feedback. Here are the connection errors I faced:
host.docker.internal:35000
for PostgreSQL.
bloom-backend | [Nest] 39 - 08/29/2024, 11:20:24 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
bloom-backend | Error: getaddrinfo ENOTFOUND host.docker.internal
bloom-backend | at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26)
bloom-backend | [Nest] 39 - 08/29/2024, 11:20:27 AM ERROR [TypeOrmModule] Unable to connect to the database.
i use linux found out that On Linux, host.docker.internal
is not available out-of-the-box. Instead, you might need to use the host’s IP address or configure Docker networking to access the host machine.
In a Docker Compose setup, host.docker.internal
isn't suitable because PostgreSQL runs in a Docker container. The recommended approach is to use postgres://postgres:postgres@db:5432/bloom
to connect to the PostgreSQL service within Docker.
Thank you @SureshPradhana you have been assigned this issue! Please follow the directions in our Contributing Guide. We look forward to reviewing your pull request shortly ✨
Support Chayn's mission? ⭐ Please star this repo to help us find more contributors like you! Learn more about Chayn here and explore our projects. 🌸
Great points @SureshPradhana. Thanks for your patience while we were out of office. This might be a Linux specific suggestion? But let's try it! We are currently making updates to our Docker set-up. I've assigned you the issue if you would like to implement these changes. Please tag me if you have any questions or if you'd like to be unassigned.
Overview:
There are two main issues in the current Docker setup:
.env
file is not being loaded, causing missing environment variables during runtime.DATABASE_URL
useshost.docker.internal:35000
, which leads to connection errors within the Docker network.These issues prevent the backend service from properly connecting to the PostgreSQL database when using Docker Compose.
Environment:
Actions Needed:
.env
file: Update thedocker-compose.yml
to include theenv_file
directive.DATABASE_URL
: Modify theDATABASE_URL
to use the correct hostname within the Docker network (db:5432
).Proposed Fix:
Load
.env
file: Add the following to theapi
service indocker-compose.yml
:Correct
DATABASE_URL
: Update theDATABASE_URL
indocker-compose.yml
: