Connecting to postgres failing

Hi!

I am running flipt through the docker container on my local machine using the latest image. I am trying to connect to my postgres database that I have set up in AWS. I can connect to this database from my local machine just fine, but no matter what I do with the environment variables, I cannot get flipt to connect to the DB. These are the commands I have tried:

docker run --rm -p 8080:8080 -p 9000:9000 -t -e FLIPT_CORS_ENABLED="true" -e FLIPT_CORS_ALLOWED_ORIGINS="*" -e FLIPT_DB_URL="postgres://postgres:REDACTED@flipt-database-cluster-instance-1.cnn0vdbejr8q.us-east-1.rds.amazonaws.com:5432/flipt" docker.flipt.io/flipt/flipt:latest

and also

docker run --rm -p 8080:8080 -p 9000:9000 -t -v $HOME/flipt:/var/opt/flipt -e FLIPT_CORS_ENABLED="true" -e FLIPT_CORS_ALLOWED_ORIGINS="*" -e FLIPT_DB_PROTOCOL="postgres" -e FLIPT_DB_HOST="flipt-database-cluster-instance-1.cnn0vdbejr8q.us-east-1.rds.amazonaws.com" -e FLIPT_DB_PORT=5432 -e FLIPT_DB_NAME="flipt" -e FLIPT_DB_USER="postgres" -e FLIPT_DB_PASSWORD="REDACTED" docker.flipt.io/flipt/flipt:latest

No matter what, the container starts, then immediately fails with

Error: getting db driver for: postgres: failed to connect to database

Is there some kind of container setting I need to provide to make this work? I have no idea where to even look for the failures since its not kicking out any logs at this stage. Any help/guidance would be appreciated.

Thank you!

@dstrohschein-equips silly question, but is your database exposed to the outside world from AWS? Are you running your Flipt docker command on your local machine and then trying to connect to your DB inside AWS? OR is everything (including Flipt via Docker) running inside AWS?

This error message Error: getting db driver for: postgres: means that it is correctly parsing the DB URL string (or protocol in the later example) and knows it should be connecting to a Postgres DB, which leads me to believe it is something network related

Hi Mark,

Yes, the DB in AWS is exposed to the outside - I can connect to it just fine from PG_Admin running on the same machine that the docker container is running (with the same credentials). My docker skills are pretty weak, so maybe there is something in the run command I need to add networking wise? I figured that if my local machine can reach the DB, the container running on that same machine should be able to - but I may be missing some kind of network configuration specific to the docker container.

EDIT for clarity:

Flipt in docker container is running on my local machine. DB is in AWS, and is exposed to the outside. I can connect to the AWS DB via PG_Admin running on my local machine, so I know that the machine can connect.

Another Update:

I ran the container without the DB commands and connected to it via the shell. The container has psql on it already, so I tried to connect to the AWS DB via psql from the container itself using the below command - and it worked. I am able to connect to the AWS DB from the container.

This makes me think I am not providing something to flipt correctly, or that I am missing a flipt configuration option some how.

psql -h flipt-database-cluster-instance-1.cnn0vdbejr8q.us-east-1.rds.amazonaws.com -p 5432 -U postgres -d flipt

Final Update:

Turns out that because I had a special character in the password, it wasn’t working. I escaped the symbol, and now flipt is happily connecting to my AWS postgres DB.

So the lesson is this - if you are using environment variables from the command line, escape special characters.

Hey!

Sorry for the delay in response! Glad you were able to figure it out.

I’ll add a note to our docs to mention to escape special chars if using them in env vars on the cli (ie for Docker)

I wonder if putting them in quotes “” would help?