Cause 1 of 5
An earlier container still holds the mapping.
docker ps -a lists containers with their port mappings, including stopped ones that still reserve an endpoint. Stop and remove it — docker stop <name> then docker rm <name> — or bring the whole stack down cleanly with docker compose down.
Cause 2 of 5
A process outside Docker owns the port.
lsof -i :8080 on macOS or Linux, netstat -ano | findstr :8080 on Windows, names the process. Stop that service, or publish your container on a different host port instead of contesting it.
Cause 3 of 5
You can simply move the host side of the mapping.
-p 8081:8080 — the left number is the host and the right is the container. Nothing inside the image or the application configuration changes, which makes this the lowest-risk fix.
Cause 4 of 5
Two services in the same compose file publish the same host port.
Only one can win. Give each a distinct host port, or remove ports: from the service that only needs to be reachable from inside the stack — containers reach each other by service name on the compose network without publishing anything to the host.
Cause 5 of 5
The daemon holds a stale endpoint after a crash.
docker compose down followed by up again clears it in most cases. If the port is still claimed with no container to match, restarting the Docker daemon releases endpoints it wrongly believes are live.