Listen tcp 0.0.0.0:5432: bind: address already in use

docker
postgresql
circle.yml

#1

Any idea why sometimes port 5432 is already in used while I stopped postresql sooner in dependencies section?

ERROR: Cannot start container 19e9fb6ebf75b5418574bc4a4b14494b9b7da0762716560a7f90aeecbef9ac2f: failed to create endpoint myproject_db_1 on network bridge: listen tcp 0.0.0.0:5432: bind: address already in use

What I do in dependencies section:

sudo service postgresql stop

  • Stopping PostgreSQL 9.5 database server
    …done.

Sometimes it’s ok, sometimes I get this error, I would like to stabilize that.


#2

Same issue here… Have you found a workaround? I guess this could work but not sure what the right command would be for port-is-opened 5432 command.

- sudo service postgresql stop
- while port-is-opened 5432; do sleep 1; done

EDIT:

That seems to work:

- sudo service postgresql stop
- while lsof -Pi :5432 -sTCP:LISTEN -t; do sleep 1; done

#3

I have seen users have more success stopping Postgres in the test section instead of the dependencies section.


#4

FWIW, even with my workaround, I’m still getting this error once in a while which is really annoying…


#5