The latest release of Docker doesn't use a virtual machine anymore, instead using a hypervisor to connect to the containers. This means I can no longer login to postgres with psql:

➜  postgres git:(master) ✗ docker run -d -p 5433:5432 db postgres
➜  postgres git:(master) ✗ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
111f3bed4c52        db                  "/docker-entrypoint.s"   17 minutes ago      Up 17 minutes>5432/tcp   zen_hugle
➜  postgres git:(master) ✗ psql -p 5433 -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 "/tmp/.s.PGSQL.5433"?

I have also tried specifying localhost as the host, but that results in a strange output:

➜  postgres git:(master) ✗ psql -h localhost -p 5433 -U postgres
psql: %

Does anyone know what to do in this case? Thank you.

  • 1
    That second case looks like you are connected. Is something not working with that?
    – JoshRagem
    Aug 9, 2016 at 12:54
  • 1
    I'm not sure it's the problem of Docker. Can you connect if you add -h localhost to the psql command?
    – dezso
    Aug 9, 2016 at 13:40
  • Sorry about the delay in responding. Yes, I can connect to the local postgres database at the port 5432. But I cannot connect to the one at 5433, which is in the docker container.
    – picardo
    Aug 14, 2016 at 0:01

1 Answer 1


I had the same problem today. I discovered that you do have to specify the -h flag for it to work:

psql -U postgres -p 5433 -h localhost

You can also use the URI style connection string:

psql postgresql://postgres:<your_password>@localhost:5433

The default is "local socket" which does not work in the case of docker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.