Home·Error messages

docker · Docker

The message

Bind for 0.0.0.0:8080 failed: port is already allocated

What it means

You asked for that host port with -p, and another container or process already holds it. Most often a container you started earlier without --rm is still there in a stopped or running state, or compose is still holding an older container. docker ps --filter publish=8080 points straight at the container publishing it; if it turns out to be an ordinary host program rather than a container, lsof -i :8080 finds it. Changing only the host side, as in -p 8081:80, gets you moving, but leaving the old container in place means the same collision next time.

The fix

docker ps --filter publish=8080
Printed by
docker
Docker
12

Docker errors only become readable once you place them in a layer — the client failing to reach the daemon, the registry refusing you, a RUN failing during the build, and a container dying the instant it starts are four different problems — and for the build and run layers the line itself is not the reason: the reason is in the output of the command that was running inside, while the cost of each fix differs by layer too.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “Bind for 0.0.0.0:8080 failed: port is already allocated” mean?

You asked for that host port with -p, and another container or process already holds it. Most often a container you started earlier without --rm is still there in a stopped or running state, or compose is still holding an older container. docker ps --filter publish=8080 points straight at the container publishing it; if it turns out to be an ordinary host program rather than a container, lsof -i :8080 finds it. Changing only the host side, as in -p 8081:80, gets you moving, but leaving the old container in place means the same collision next time.

Q. How do I fix it?

docker ps --filter publish=8080 — before running it, check the explanation above for what this command discards.

Q. Which tool prints this?

docker. It sits under Docker, and the message runs to 8 words.

Errors nearby