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
3
Answers
Then you just bind another port
-p 5001:5000
basically means, bind port 5001 in myhost machine
with the port 5000 in the container. Since port 5000 already used in your host machine, then u can bind with another port example: port 5001You 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
You’ll probably see your old container listed and that it’s using port 5000.
Remove it with
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 thisFirst find what process is occupying the port:
ss -aultnp|grep 5000
Get the program: pid
ps -ef|grep pid
Find the program occupying the port