I am trying to troubleshoot a connection issue between my postgres client and my postgres docker container (locally).
To start my docker container I ran the following command:
docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=docker postgres:9.4
The container successfully starts.
➜ ~ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
14310d9f0ece postgres:9.4 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:5432->5432/tcp postgres
I then use my psql client which I installed via homebrew to attempt to connect and it simply hangs:
➜ ~ psql --version
psql (PostgreSQL) 9.4.22
➜ psql -h 127.0.0.1 -p 5432
// hangs
I have also attempted to use pgAdmin to connect which also is unable to connect. There is no log activity in the container that indicates an attempted connection. What is frustrating is that I can successfully ping the container:
➜ ~ nc -vz localhost 5432
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif lo0
src ::1 port 51856
dst ::1 port 5432
rank info not available
TCP aux info available
Connection to localhost port 5432 [tcp/postgresql] succeeded!
I also checked to see if anything else could possibly be listening on 5432 but it looks like it is only docker
➜ ~ lsof -n -i :5432 | grep LISTEN
com.docke 13037 steve 27u IPv4 0xd8d4bc5463376f87 0t0 TCP *:postgresql (LISTEN)
com.docke 13037 steve 115u IPv6 0xd8d4bc5462ccdd07 0t0 TCP [::1]:postgresql (LISTEN)
Looking for any advice on how else to troubleshoot this issue.
Best Answer
OK well after spending about a day on this, I came across a github issue in docker where a number of users reported network issues in docker on a mac. I restarted my laptop and now I can connect no problem.
https://github.com/docker/for-mac/issues/3350
I am using Docker version 18.09.2, build 6247962 on a Mojave Macbook Pro. I will make sure to add myself to the github issue too.