Solution for error with for db Cannot start service db: Ports are not available: listen tcp 0.0.0.0:5432: bind: address already in use in Docker

error#

When I tried to run jupyter with Docker, I got the following error and could not start it.

terminal


ERROR: for db  Cannot start service db: Ports are not available: listen tcp 0.0.0.0:5432: bind: address already in use
ERROR: Encountered errors while bringing up the project.

When I read the error message, it said that the port number of 5432 was used and I could not start it.

solution##

First, identify the application that is occupying the port. In this case, it's 5432, so let's run it below.

terminal


$ sudo lsof -i : 5432
Password:
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
postgres 124 postgres    4u  IPv6 0xda3bd3018b955b25      0t0  TCP *:postgresql (LISTEN)
postgres 124 postgres    5u  IPv4 0xda3bd3018b95cb95      0t0  TCP *:postgresql (LISTEN)

When I entered the password I set for Password, these messages came out. It seems that postgres is running and Docker doesn't work. Let's stop this.

terminal


$ sudo kill 124

Make sure you don't mistake it for 5432 here. The number to kill is 124 in the part called PID. When I tried to move it again, it was done.

Recommended Posts

Solution for error with for db Cannot start service db: Ports are not available: listen tcp 0.0.0.0:5432: bind: address already in use in Docker
`bind': Address already in use --bind (2) for 127.0.0.1:3000 (Errno :: EADDRINUSE) How to deal with the error
[Cloud9] Address already in use [Solution]
Docker Compose does not start with docker.credentials.errors.InitializationError error message