docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:5000: bind: address already in use [duplicate]
I am new and trying out this tutorial from DigitalOcean but when I do docker run -p 5000:5000 flask_demo:v0
, I am getting the following error.
docker:
Error response from daemon: Ports are not available: listen tcp 0.0.0.0:5000: bind: address already in use.
Please help me
Solution 1:
You probably ran the application once before. When a docker container exits, it's still on your machine and has the port allocated.
To see what containers you have, run the command
docker ps -a
You'll probably see your old container listed and that it's using port 5000. Remove it with
docker rm <container name>
Now the port is available again.
If you don't think you'll need to look at your container after it exits, you can add the --rm
parameter to the docker run command and it'll be automatically removed when it exits. Like this
docker run -p 5000:5000 --rm flask_demo:v0