chaynHQ / bloom-backend

Code for the backend / API of the Bloom service
https://bloom.chayn.co/
MIT License
18 stars 30 forks source link

Docker Compose doesn't load .env file and incorrect DATABASE_URL configuration #588

Open SureshPradhana opened 1 month ago

SureshPradhana commented 1 month ago

Overview:

There are two main issues in the current Docker setup:

  1. The .env file is not being loaded, causing missing environment variables during runtime.
  2. The DATABASE_URL uses host.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:

Proposed Fix:

  1. Load .env file: Add the following to the api service in docker-compose.yml:

    env_file:
     - .env
  2. Correct DATABASE_URL: Update the DATABASE_URL in docker-compose.yml:

    DATABASE_URL=postgres://postgres:postgres@db:5432/bloom
SureshPradhana commented 1 month ago

Hi, can you confirm if the issue I reported is correct? If so, I'd like to work on it.

kyleecodes commented 2 weeks ago
  1. The .env file is not being loaded, causing missing environment variables during runtime.
  2. The DATABASE_URL uses host.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.

SureshPradhana commented 2 weeks ago

Hi @kyleecodes,

Thanks for the feedback. Here are the connection errors I faced:

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.