Docker & Postgres: Failed to bind tcp 0.0.0.0:5432 to an address that is already in use

Problem

I try to run postgres in a docker container on my Mac, but I keep getting the following error message

docker: error response from the daemon: the driver did not program the external connection at the postgres endpoints (8392b9e5cfaa28f480fe1009dee461f97e82499726f4afc4e916358dd2d2f61e): Error starting user proxy userland: it was not possible to bind the address tcp 0.0.0.0:5432 already.

I have postgres installed locally, but I stopped it and started

pg_ctl status 

returns

pg_ctl: server is down

I checked the following to check what works on 5432

 lsof -i tcp:5432 

&

 netstat -anp tcp | grep 5432 

and nothing works on the port.

Version

Mac - OS X El Capitan Version 10.11.2

PostgreSQL - 9.5

Docker - Docker version 1.12.0-rc2, compilation 906eacd, experimental

+10
source share
1 answer

If you run lsof -i :5432 on the host, you will see which process is associated with the port.

Some kind of Postgres instance is working. You can execute kill <pid> to kill it if you want. You can also use 5432 instead of 5432:5432 in the docker command or in the docker-compose file and let docker automatically select the host port.

+20
source

All Articles