skip to Main Content

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


  1. Then you just bind another port

    docker run -p 5001:5000 flask_demo:v0
    

    -p 5001:5000 basically means, bind port 5001 in my host 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 5001

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
  3. First 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search