0

I wanted to run postgres database in docker container. I pulled the newest image of postgres:

docker pull postgres

And started container out of it:

docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 postgres

After that I tried to access the postgres:

psql -h localhost -U postgres -d postgres

And connection failed:

psql: error: could not connect to server: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

I don't understand why?

[EDIT] I tried it on Windows 10 Pro with Docker Toolbox and it fails, however on Ubuntu 18.04 works fine.

Gaker
  • 1
  • 1
  • Are you using Docker Toolbox, perhaps on a Windows 7 system? Did you wait a minute or so for the database to start up? – David Maze Mar 17 '20 at 14:03
  • Yes, I use Docker Toolbox on Windows 10 and I waited more than one minute :/ – Gaker Mar 19 '20 at 08:04
  • I tried on Ubuntu 18.04.4 LTS and it works perfectly fine, perhaps it is the matter of VM for Docker Toolbox on Windows. – Gaker Mar 19 '20 at 10:37
  • If you're using Docker Toolbox, nothing will be `localhost`; you need to find the Docker VM's IP address with `docker-machine ip` and give that to `psql` where you have `localhost` now. – David Maze Mar 19 '20 at 10:50
  • Thank You, that's what I just figured out :) You are right. – Gaker Mar 19 '20 at 11:02

0 Answers0