I spent more than 24 hours trying to figure out why a flask app is unable to communicate with a postgres sql database while both are shipping in docker containners.

docker exec -it containaer_id command

run inside a container

fix the problem with docker port for postgres

1rst Attempt :

from this answer on stackoverflow i need to check my databse url, the dabase is correct

change database uri to ENV DATABASE_URL=”postgresql://espoir_mur:9874@”

2nd Attempt :

Try this answer here it’ said that i should Y run a container called dadarek/wait-for-dependencies as a mechanism to wait for services to be up(in your case, postgres).

but it doesn’t works also.

keep debugging

3rd attempt:

I go and read about race condition with the python app and the docker container here I need to write a python script that check if the port is open , but the script doesn’t work also.

I’m sure that the prosgres database is up but I’m unable to connect to it . how can i conenct to it ?? is it a problem of url?? sound like. let go deeper This user also have the same error

4th attempt:

usinng this url schema


this question gives also another explanation it said : Postgres is not running in the same container as the flask application, that why it can not be acceded via localhost . we should find the ip adress of the docker container with flask and add it , or just add postgres or volume_name in place of localhost. And finaly this solve my problem. Okey…

####I’m safe now