portfind

Fix Docker "port is already allocated" and "address already in use"

Updated

docker run -p or docker compose up failed with one of these errors:

errors
Bind for 0.0.0.0:5432 failed: port is already allocated

listen tcp4 0.0.0.0:5432: bind: address already in use

Which error do you have?

ErrorWhat is holding the port
port is already allocatedAnother container publishes the same host port.
bind: address already in useA program on your machine (not in Docker), for example a locally installed PostgreSQL.

If another container has it

If it belongs to another Compose project, stop that project from its folder with docker compose down, so its other containers stop too.

A container with a restart policy (restart: always or unless-stopped) starts again when Docker restarts. To stop that: docker update --restart=no <container-name>.

find the container publishing port 5432
docker ps --filter "publish=5432"
stop it
docker stop <container-name>

If a program on your machine has it

Find it like any other port and stop it: see the guides for Windows, macOS and Linux. A database installed as a service should be stopped as a service, not killed.

Or publish on a different host port

The container can keep its port; only the host side changes. Here the database is reachable on localhost:5433:

docker run
docker run -d -p 5433:5432 postgres:16
compose.yaml
services:
  db:
    image: postgres:16
    ports:
      - "5433:5432"

See container names instead of com.docker.backend

Ordinary port tools show Docker's own process (com.docker.backend, docker-proxy) for every published port, and killing that would stop all of Docker. portfind asks Docker which container publishes each port, shows the container, image and Compose project, and stops just that container when you choose it.

Windows (PowerShell)
irm https://raw.githubusercontent.com/rpratap2111/portfind/main/install.ps1 | iex
Linux / macOS
curl -fsSL https://raw.githubusercontent.com/rpratap2111/portfind/main/install.sh | sh