Docker. Error: Cannot start container: port has already been allocated

One reason I've come across is that in some versions of docker (pre 1.2), there's a bug where if it detects a port is already assigned (perhaps even to a system, not docker run, program like nginx) it will continue to fail to reassign it even if you stop the conflicting thing, until you restart docker.

Check that nothing else is using the port, then restart docker. (service docker.io restart)

reference: https://github.com/docker/docker/issues/6476


From the docker ps output, there is a container which is listening on port 5000 as you can see from the 0.0.0.0:5000->5000/tcp under the ports column.

You can kill this container with docker kill container. At which point it will free up the port. In your case:

docker kill 3fdfc9ecf30f

I've fixed it by restarting the docker service:

sudo service docker restart

Note: I'm using Linux Mint, by the way.

Tags:

Docker