spacegoing
spacegoing

Reputation: 5306

Psql Docker: could not connect to server: No such file or directory

I created a container using following command:

docker run -itd --name jkdb -e POSTGRES_PASSWORD=123 -v /home/lchang/jkrug/data:/var/lib/postgresql/data -p 5532:5432 -d postgres

I checked in container and psql does listen to 5432 in container.

However, when I try to connect from my host by following command, I got an error:

psql -p 5532 -U postgres
psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5532"?

I searched many posts but none of them is same with my case. Any idea? Thanks!

Upvotes: 14

Views: 12322

Answers (2)

balloon
balloon

Reputation: 91

Same issue. I am running postgres with docker.

docker run -e POSTGRES_PASSWORD=xxx -d -p 5432:5432 --name postgres postgres:11.10

can't connect with command psql postgres postgres, but was able to connect with command psql -h 0.0.0.0 postgres postgres. Don't understand the reason, but hope it helps you.

Upvotes: 3

spacegoing
spacegoing

Reputation: 5306

It does not make any sense but after I specify the host IP is 0.0.0.0 I can connect to docker.

Upvotes: 31

Related Questions