Docker Error bind: address already in use

483,544

Solution 1

In your case it was some other process that was using the port and as indicated in the comments, sudo netstat -pna | grep 3000 helped you in solving the problem.

While in other cases (I myself encountered it many times) it mostly is the same container running at some other instance. In that case docker ps was very helpful as often I left the same containers running in other directories and then tried running again at other places, where same container names were used.

How docker ps helped me:

docker rm -f $(docker ps -aq) is a short command which I use to remove all containers.

Edit: Added how docker ps helped me.

Solution 2

This helped me:

docker-compose down  # Stop container on current dir if there is a docker-compose.yml
docker rm -fv $(docker ps -aq)  # Remove all containers
sudo lsof -i -P -n | grep <port number>  # List who's using the port

and then: kill -9 <process id> (macOS) or sudo kill <process id> (Linux).

Source: comment by user Rub21.

Solution 3

I had the same problem. I fixed this by stopping the Apache2 service on my host.

Solution 4

I had same problem, docker-compose down --rmi all (in the same directory where you run docker-compose up) helps

UPD: CAUTION - this will also delete the local docker images you've pulled (from comment)

Solution 5

For Linux/Unix:

Simple search for linux utility using following command

netstat -nlp | grep 8888

It'll show processing running at this port, then kill that process using PID (look for a PID in row) of that process.

kill PID
Share:
483,544

Related videos on Youtube

Ngoral
Author by

Ngoral

Updated on April 17, 2022

Comments

  • Ngoral
    Ngoral about 2 years

    When I run docker-compose up in my Docker project it failes with the following message:

    Error starting userland proxy: listen tcp 0.0.0.0:3000: bind: address already in use
    

    netstat -pna | grep 3000 shows this:

    tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      -  
    

    I've already tried docker-compose down, but it doesn't help.

    • BMitch
      BMitch almost 8 years
      Run a sudo netstat -pna | grep 3000 to get the process that's listening.
    • techtabu
      techtabu almost 8 years
      Your output shows some other process is listening on port 3000 already. Can you use some other port? Try with sudo to see the process name.
    • Ngoral
      Ngoral almost 8 years
      Yep, there was ntop on this port. Thanx! I didn't know sudo can change output :)
    • Neil McGuigan
      Neil McGuigan almost 6 years
      For me it's port 8888 which is docker proxy
    • julianm
      julianm over 4 years
      I fixed this same issue in this answer: stackoverflow.com/a/58772307/3530707
  • Ngoral
    Ngoral almost 7 years
    Actually, I have this problem often. And nothing, but docker-compose down helps
  • Ayushya
    Ayushya almost 7 years
    That is sure to help, on the condition that you are running it in the same directory where you ran docker-compose up. While I recommend in my answer to find the container which is already running and take desired action. I felt appropriate to remove them, if someone does not want to remove, then there's instead using rm use stop to stop them.
  • Emanuel Fontelles
    Emanuel Fontelles over 5 years
    I have another server running on the same port that tensorflow/tensorflow image are will run. How can I setup my image to run in another port. I've tried this: docker run -it -d -p 8888:8000 tensorflow/tensorflow I binded port 8888 from my image to 8000 on client, but don't work.
  • Ayushya
    Ayushya over 5 years
    @EmanuelFontelles When trying to debug, do not use -d option. Now, ports are exposed as HOST:CONTAINER. Thus you should run docker run -it -p 8000:8888
  • Ngoral
    Ngoral about 5 years
    Yes, it always helps, but down is the last thing you usually want to do. Losing the current state is not a piece of sugar.
  • Ryan Walker
    Ryan Walker over 4 years
    docker rm -fv $(docker ps -aq) this line was all I needed. Thanks
  • Alexander
    Alexander over 4 years
    Restarting helped for me too. Thanks.
  • Micah Simmons
    Micah Simmons almost 4 years
    This will also delete the local docker images you've pulled so use it with caution
  • Mr. E
    Mr. E almost 4 years
    lsof worked a charm, killed the process and back in action....
  • Mustapha-Belkacim
    Mustapha-Belkacim almost 4 years
    this was my problem too, I forgot I installed Apache
  • Mark Wardell
    Mark Wardell over 3 years
    i see how to restart a container. How to restart docker?
  • Roy
    Roy over 3 years
    netstat shows the PID/program(e.g. 2714/splunkd).sudo kill 2714 works. Thanks.
  • Ahmed Nour Jamal El-Din
    Ahmed Nour Jamal El-Din over 3 years
    You should have mentioned it will delete the local docker images in the answer.
  • Alferd Nobel
    Alferd Nobel over 3 years
    Spot on ! your solution helped .
  • r34
    r34 about 3 years
    This works for me, but then I can't restart apache2 correctly, when the docker container is running
  • mufazmi
    mufazmi almost 3 years
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
  • kiran
    kiran almost 3 years
    FR: To stop Apache 2 web server, enter: # /etc/init.d/apache2 stop
  • baponkar
    baponkar almost 3 years
    sudo service apache2 stop && sudo service nginx stop worked for me.
  • Arefe
    Arefe almost 3 years
    Interestingly, each time I kill, it assigned to another port that I find very wired.
  • Peko Chan
    Peko Chan almost 3 years
    sudo lsof -i -P -n | grep <port number> -> this one was good enough to debug on OSX ty :)
  • kojot
    kojot over 2 years
    sudo systemctl restart docker , had the same problem after installing firewalld
  • Shiro
    Shiro over 2 years
    make sure comment or remove that line of code that used port, if not it will keep trying use that port.
  • acedanger
    acedanger over 2 years
    somehow apache was enabled after an update/restart. it was listening on port 80 and impeding an important container from running.
  • Markus Zeller
    Markus Zeller over 2 years
    Apache2 came on my machine with installation of PHP8. The problem occured after reboot, when apache2 was auto started on system start. As I don't need it locally on my computer I just removed it via sudo apt remove apache2.
  • Ilyich
    Ilyich over 2 years
    @r34 This is expected behavior. You can run apache2 either on host OS or via Docker, not both of them simultaneously.
  • Sandra
    Sandra over 2 years
    another one to try sudo httpd -k stop as my php switching script re-started apache for me...
  • Ondiek Elijah
    Ondiek Elijah over 2 years
    This one worked for me, I happened to be repeating the ports in my docker-compose.yml
  • General Grievance
    General Grievance about 2 years
  • Leo Messi
    Leo Messi about 2 years
    the best answer for Mac users including M1 chips like my case.
  • Ali Mrj
    Ali Mrj about 2 years
    Thanks, in my case it was sudo service redis stop
  • lortschi
    lortschi almost 2 years
    nice, thx! This was the right fix.
  • Holly Cummins
    Holly Cummins almost 2 years
    Thank you for this! It saved me a lot of headaches.
  • ניר
    ניר almost 2 years
    those who runs on ubuntu willl want to add sudo between each call to docker: sudo docker rm -f $(sudo docker ps -aq)
  • Tim Bogdanov
    Tim Bogdanov almost 2 years
    PhpStorm was the culprit
  • Roi Mulia
    Roi Mulia almost 2 years
    Wow, great catch on the 5000!
  • n0nSmoker
    n0nSmoker almost 2 years
    For macOS the last step should be google that process first =) This is my case developer.apple.com/forums/thread/682332