Docker Error bind: address already in use
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
Related videos on Youtube
Ngoral
Updated on April 17, 2022Comments
-
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 almost 8 yearsRun a
sudo netstat -pna | grep 3000
to get the process that's listening. -
techtabu almost 8 yearsYour 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 almost 8 yearsYep, there was ntop on this port. Thanx! I didn't know
sudo
can change output :) -
Neil McGuigan almost 6 yearsFor me it's port 8888 which is docker proxy
-
julianm over 4 yearsI fixed this same issue in this answer: stackoverflow.com/a/58772307/3530707
-
-
Ngoral almost 7 yearsActually, I have this problem often. And nothing, but
docker-compose down
helps -
Ayushya almost 7 yearsThat 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 usingrm
usestop
to stop them. -
Emanuel Fontelles over 5 yearsI 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 over 5 years@EmanuelFontelles When trying to debug, do not use
-d
option. Now, ports are exposed asHOST:CONTAINER
. Thus you should rundocker run -it -p 8000:8888
-
Ngoral about 5 yearsYes, 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 over 4 years
docker rm -fv $(docker ps -aq)
this line was all I needed. Thanks -
Alexander over 4 yearsRestarting helped for me too. Thanks.
-
Micah Simmons almost 4 yearsThis will also delete the local docker images you've pulled so use it with caution
-
Mr. E almost 4 yearslsof worked a charm, killed the process and back in action....
-
Mustapha-Belkacim almost 4 yearsthis was my problem too, I forgot I installed Apache
-
Mark Wardell over 3 yearsi see how to restart a container. How to restart docker?
-
Roy over 3 yearsnetstat shows the PID/program(e.g. 2714/splunkd).sudo kill 2714 works. Thanks.
-
Ahmed Nour Jamal El-Din over 3 yearsYou should have mentioned it will delete the local docker images in the answer.
-
Alferd Nobel over 3 yearsSpot on ! your solution helped .
-
r34 about 3 yearsThis works for me, but then I can't restart apache2 correctly, when the docker container is running
-
mufazmi almost 3 yearsWhile 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 almost 3 yearsFR: To stop Apache 2 web server, enter: # /etc/init.d/apache2 stop
-
baponkar almost 3 years
sudo service apache2 stop && sudo service nginx stop
worked for me. -
Arefe almost 3 yearsInterestingly, each time I kill, it assigned to another port that I find very wired.
-
Peko Chan almost 3 years
sudo lsof -i -P -n | grep <port number>
-> this one was good enough to debug on OSX ty :) -
kojot over 2 years
sudo systemctl restart docker
, had the same problem after installing firewalld -
Shiro over 2 yearsmake sure comment or remove that line of code that used port, if not it will keep trying use that port.
-
acedanger over 2 yearssomehow apache was enabled after an update/restart. it was listening on port 80 and impeding an important container from running.
-
Markus Zeller over 2 yearsApache2 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 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 over 2 yearsanother one to try
sudo httpd -k stop
as my php switching script re-started apache for me... -
Ondiek Elijah over 2 yearsThis one worked for me, I happened to be repeating the ports in my docker-compose.yml
-
General Grievance about 2 yearsSo did this person: stackoverflow.com/a/59797983/4294399
-
Leo Messi about 2 yearsthe best answer for Mac users including M1 chips like my case.
-
Ali Mrj about 2 yearsThanks, in my case it was
sudo service redis stop
-
lortschi almost 2 yearsnice, thx! This was the right fix.
-
Holly Cummins almost 2 yearsThank you for this! It saved me a lot of headaches.
-
ניר almost 2 yearsthose who runs on ubuntu willl want to add sudo between each call to docker:
sudo docker rm -f $(sudo docker ps -aq)
-
Tim Bogdanov almost 2 yearsPhpStorm was the culprit
-
Roi Mulia almost 2 yearsWow, great catch on the 5000!
-
n0nSmoker almost 2 yearsFor macOS the last step should be google that process first =) This is my case developer.apple.com/forums/thread/682332