Docker Community Forums

Share and learn in the Docker community.

Unable to connect to Postgres inside Docker container

I’ve created a docker image for postgres and run it with the following command:

docker run --name sqlalchemy-orm-psql \
-e POSTGRES_DB=sqlalchemy \
-p 5432:5432 \
-d postgres

As you can see, it’s now running sucessfully:

Despite this I’m getting a “Connection refused” error when trying to connect to localhost:5432. My understanding is that connections to should be forwarded to Docker on Please can somebody confirm if this correct? Also, running netstat doesn’t show any instance running on my localhost. I’m new to Docker and struggling to troubleshoot this.

I’ve tried to post several more images but new users are only allowed to post a single image. Anyway, if anybody could point me in the right direction I’d appreciate it.


I finally managed to solve the issue. As I’m running docker toolbox on Windows home it appears that I have to connect to the ip returned from docker-machine ip instead of localhost.

Thanks to this article for explaining: