Fix Docker "port is already allocated" and "address already in use"
docker run -p or docker compose up failed with one of these errors:
Bind for 0.0.0.0:5432 failed: port is already allocated
listen tcp4 0.0.0.0:5432: bind: address already in useWhich error do you have?
| Error | What is holding the port |
|---|---|
| port is already allocated | Another container publishes the same host port. |
| bind: address already in use | A 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>.
docker ps --filter "publish=5432"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 -d -p 5433:5432 postgres:16services:
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.
irm https://raw.githubusercontent.com/rpratap2111/portfind/main/install.ps1 | iexcurl -fsSL https://raw.githubusercontent.com/rpratap2111/portfind/main/install.sh | sh