Linux bind address already in use

Docker Error bind: address already in use

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.

35 Answers 35

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 # List who's using the port 

and then: kill -9 (macOS) or sudo kill (Linux).

sudo lsof -i -P -n | grep -> this one was good enough to debug on OSX ty 🙂

For macOS the last step should be google that process first =) This is my case developer.apple.com/forums/thread/682332

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.

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.

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.

@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

those who runs on ubuntu willl want to add sudo between each call to docker: sudo docker rm -f $(sudo docker ps -aq)

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

Читайте также:  What is mysql server in linux

somehow apache was enabled after an update/restart. it was listening on port 80 and impeding an important container from running.

You can kill the process listening on that port easily with one command below :

-9 is for hard kill without checking any deps.

(Not related, but might be useful if its PORT 5000 mystery) — the culprit process is due to Mac OS monterery.

The port 5000 is commonly used to serve local development servers. When updating to the latest macOS operating system, I was unable the docker to bind to port 5000, because it was already in use. (You may find a message along the lines of Port 5000 already in use.)

By running lsof -i :5000, I found out the process using the port was named ControlCenter, which is a native macOS application. If this is happening to you, even if you use brute force (and kill) the application, it will restart itself. In my laptop, lsof -i :5000 returns that Control Center is being used by process id 433. I could do killall -p 433, but macOS keeps restarting the process.

The process running on this port turns out to be an AirPlay server. You can deactivate it in

System Preferences › Sharing, and unchecking AirPlay Receiver to release port 5000.

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)

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.

Simple search for linux utility using following command

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

In some cases it is critical to perform a more in-depth debugging to the problem before stopping a container or killing a process.

Consider following the checklist below:

1) Check you current docker compose environment
Run docker-compose ps .
If port is in use by another container, stop it with docker-compose stop or remove it by replacing stop with rm .

2) Check the containers running outside your current workspace
Run docker ps to see list of all containers running under your host.
If you find the port is in use by another container, you can stop it with docker stop .
(*) Because you’re not under the scope of the origin compose environment — it is a good practice first to use docker inspect to gather more information about the container that you’re about to stop.

Читайте также:  Linux как открыть ftp

3) Check if port is used by other processes running on the host
For example if the port is 6379 run:

$ sudo netstat -ltnp | grep ':6379' tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 915/redis-server 12 tcp6 0 0 ::1:6379 . * LISTEN 915/redis-server 12 

(*) You can also use the lsof command which is mainly used to retrieve information about files that are opened by various processes (I suggest running netstat before that).

So, In case of the output above the PID is 915 . Now you can run:

$ ps j 915 PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 1 915 915 915 ? -1 Ssl 123 0:11 /usr/bin/redis-server 127.0.0.1:6379 

And see the ID of the parent process ( PPID ) and the execution command.
You can also run: $ pstree -s to a visual display of the process and its related processes.

In our case we can see that the process probably is a daemon (PPID is 1) — In that case consider running:
A) $ cat /proc//status in order to get a more in-depth information about the process like the number of threads spawned by the process, its capabilities, etc’.
B) $ systemctl status in order to see the systemd unit that caused the creation of a specific process. If the service is not critical — you can stop and disable the service.

4) Restart Docker service
Run: sudo service docker restart .

5) You reached this point and..
Only if its not placing your system at risk — consider restarting the server.

Источник

ssh -L (error: bind: Address already in use)

Pretty simple, I know that this has happened to me before. Couldn’t find a good answer on AU. I was running an ssh session with ports bound:

I just lost my connection. When I try to reconnect using the same command, I get the following error:

bind: Address already in use channel_setup_fwd_listener: cannot listen to port: 3000 

How do I reset ssh on my machine to allow the port to be bound again? Resetting the local machine works.

4 Answers 4

Couldn’t you just kill whatever is using that port?

 lsof -ti:5901 | xargs kill -9 

lsof -ti:5901 to find whatever is using port 5901 .

Pass the whole thing to kill -9 to kill whatever was using port 5901 .

Replace with the port you want to open up again.

Yes, you could change the port number to whatever port is being blocked. I am going to mark this as the answer.

If you are cautious and/or forgetful like me, you may wish to run lsof on its own and find out what the process is before killing it. lsof -ti:5901 will return a process number, which you then pass to kill -9

Читайте также:  Linux активировать сетевой интерфейс

There is no reason to kill -9 unless the program is completely unresponsive. Killing a process with signal #9 (SIGKILL) terminates it immediately without giving the process a chance to flush buffers, close filehandles and sockets, remove temporary files, etc., all of which the process can do if you use kill (defaults to SIGTERM), followed by kill -1 (SIGHUP; hangup) and kill -2 (SIGINT; what Ctrl+C sends) if that doesn’t work, and finally kill -9 if nothing else works.

Источник

Bind failed: Address already in use

I faced the same issue when I closed the server program with client program still running. This put the socket into TIME_WAIT state. Here’s an elaborate discussion of the problem: How to forcibly close a socket in TIME_WAIT?

Why was this question closed? It covers a common issue for socket programming, and the the questions’ answers are useful and correct. It certainly helped me.

12 Answers 12

Everyone is correct. However, if you’re also busy testing your code your own application might still «own» the socket if it starts and stops relatively quickly. Try SO_REUSEADDR as a socket option:

What exactly does SO_REUSEADDR do?

This socket option tells the kernel that even if this port is busy (in the TIME_WAIT state), go ahead and reuse it anyway. If it is busy, but with another state, you will still get an address already in use error. It is useful if your server has been shut down, and then restarted right away while sockets are still active on its port. You should be aware that if any unexpected data comes in, it may confuse your server, but while this is possible, it is not likely.

It has been pointed out that «A socket is a 5 tuple (proto, local addr, local port, remote addr, remote port). SO_REUSEADDR just says that you can reuse local addresses. The 5 tuple still must be unique!» by Michael Hunter (mphunter@qnx.com). This is true, and this is why it is very unlikely that unexpected data will ever be seen by your server. The danger is that such a 5 tuple is still floating around on the net, and while it is bouncing around, a new connection from the same client, on the same system, happens to get the same remote port. This is explained by Richard Stevens in «2.7 Please explain the TIME_WAIT state.».

Источник

Оцените статью
Adblock
detector