using dbt cli in Docker Compose container - database connection issues

The problem I’m having…

I am using a dbt core project inside of a docker compose container. I am trying to connect to my target database (postgres). I keep getting connection issues.

The context of why I’m trying to do this…

We are trying to use Mage.ai in a Docker Compose template to load from a AWS RDS MS SQL Server Express database to a localhost via port forwarding Postgres Target database. The Mage project can connect to bothe the RDS Source and the Postgres Target databases. I just can get the dbt connection to the Target Postgres database to work.

What I’ve already tried …

  • using the .env file for the Mage.ai project Environmental variables reference in the profiles.yml for the postgres connection - errors that it can find the environmental variables
  • setting the docker-compose.yml ports to add in the 5432 postgres port and setting the profiles.yml postges host to host.docker.internal - errors that it doesn’t recognize host.docker.internal
    – using same seup as above but changing the profiles.yml postgres host to localhost - dbt debug says connection closes prematurely

Some example code or error messages

Put code inside backticks
  to preserve indentation
    which is especially important 
      for Python and YAML!