phenderbender
phenderbender

Reputation: 785

Docker Error - 5432: bind: address already in use

I used to be able to run docker-compose using 5432:5432 port mapping, but am recently getting this error:

Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use

I've gone through all of the older posts relating to this issue but have yet to be able to solve this.

I've been driving myself mad with this error for the past week trying to figure out how to stop whatever process is running with no avail.

I've tried running

lsof -i tcp:5432

which returns no results (as long as my pgadmin/server is not running)

I've also seen other posts mention running

netstat -anp tcp | grep 5432

which does return two lines:

tcp4       0      0  *.5432                 *.*                    LISTEN     
tcp6       0      0  *.5432                 *.*                    LISTEN 

But I'm not entirely sure what to do with that output?

Upvotes: 6

Views: 17392

Answers (2)

Renisha Fernandes
Renisha Fernandes

Reputation: 27

There is a possibility that this might be happening due to multiple instances of postgres running on your machine.

In my case, I had previously installed postgres which was always running on the machine because of which docker-based postgres was unable to start due to the above error. Uninstalling previously installed postgres helped to resolve the issue.

Upvotes: 1

Tov Aqulic
Tov Aqulic

Reputation: 325

Run lsof -i tcp:5432 with sudo rights:

sudo lsof -i tcp:5432

A process (very likely PostgreSQL) is listening on port 5432, preventing another to listen on that port. Stop the process, e.g. with systemctl, then you will be able to start your docker PostgreSQL.

Upvotes: 15

Related Questions