Docker Community Forums

Share and learn in the Docker community.

Connecting to postres on host from inside a container

Hello everyone,
I’m trying to connect to postgres which is running on my host machine, from inside a containerized application, but my app framework is giving me a “connection refused” error. This command i’m using to run the container is:

docker container run --add-host=host.docker.internal:host-gateway --env SECRET_KEY_BASE="secret" --env DATABASE_URL="ecto://postgres:postgres@localhost:5432/my_app_db" --rm -it -p --name app phoenix-app:v1.0.0

where phoenix-app:v1.0.0 is the image i created from the app’s source. Am I doing something wrong?

Would appreciate any insight, thanks!