Fix "Address Already in Use" (EADDRINUSE): Find and Kill the Process on a Port
"Address already in use" (Node.js shows EADDRINUSE, Docker shows port is already allocated) means another process is already listening on that port. Find it: on Linux run sudo ss -ltnp | grep :8080, on Mac lsof -i :8080, and on Windows netstat -ano | findstr :8080. Then stop that process the proper way (systemctl stop, docker stop, or Ctrl+C), or run your app on a different port.
Quick answer
sudo ss -ltnp | grep :8080 # Linux: who listens on 8080?
lsof -i :8080 # Mac (and Linux)
docker ps --filter "publish=8080" # is it a container?
sudo systemctl stop jenkins # stop a service properly
kill 23456 # or stop one process by PID
A live example first
A student installs Jenkins on an Ubuntu EC2 instance, then tries to start a Spring Boot app:
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8080 was already in use.
Find out who has the port:
sudo ss -ltnp | grep :8080
LISTEN 0 50 *:8080 *:* users:(("java",pid=1187,fd=8))
It is a Java process, PID 1187. Which one?
ps -o pid,user,cmd -p 1187
PID USER CMD
1187 jenkins /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --httpPort=8080
It is Jenkins, which also uses port 8080 by default. Killing it would only work until the next reboot. Better to give one of them a new port. We start Spring Boot on 8081:
java -jar orders-api.jar --server.port=8081
Friends, always find out who owns the port before you kill anything. It may be something important.
Why does this happen?
Only one process can listen on a port. Find the PID, stop it the right way, or use another port.
A program "listens" on an IP address and port, for example 0.0.0.0:8080. The operating system gives each listening port to only one socket, so a second program asking for the same port gets refused. The usual reasons are:
- an old copy of your own app is still running (in another terminal, in PM2, or started with
nohup), - a service already uses that port (Jenkins and Tomcat on 8080, Apache or nginx on 80),
- a Docker container publishes that port on the host.
How do I fix it step by step?
- Read the port number in the error.
- Find the process with the command for your system (below).
- Look at the program name and user to decide what it is.
- If it is an old copy of your app, stop it.
- If it is a system service you do not need,
sudo systemctl stop <name>andsudo systemctl disable <name>. - If it is a container,
docker stop <name>. - If you need both programs, change the port of one of them.
- Start your app again and confirm with
ss -ltnp.
Find the process on each system
Linux (Ubuntu, Amazon Linux, RHEL)
sudo ss -ltnp | grep :3000
sudo lsof -i :3000
sudo fuser -v 3000/tcp
sudo matters. Without it, you cannot see processes owned by other users.
macOS
lsof -nP -iTCP:3000 -sTCP:LISTEN
kill <PID>
On macOS Monterey and later, AirPlay Receiver uses port 5000 and sometimes 7000. Flask's default is 5000, so Flask users often see this error. Change the Flask port, or turn off AirPlay Receiver in System Settings.
Windows (PowerShell or Command Prompt)
netstat -ano | findstr :8080
tasklist /FI "PID eq 4321"
taskkill /PID 4321 /F
PowerShell also has Get-NetTCPConnection -LocalPort 8080 | Select-Object OwningProcess.
Docker
Error response from daemon: driver failed programming external connectivity:
Bind for 0.0.0.0:8080 failed: port is already allocated
docker ps --format "table {{.Names}}\t{{.Ports}}" | grep 8080
docker stop old-api
Or keep both and map a new host port: docker run -p 8081:8080 orders-api. Only the left number (the host port) must be free.
Change the port in your stack
| Stack | Default port | How to change |
|---|---|---|
| Node.js / Express | 3000 | PORT=3001 node server.js (if the code reads process.env.PORT) |
| React / Vite dev server | 5173 / 3000 | npm run dev -- --port 5174 |
| Python Flask | 5000 | flask run --port 5001 |
| Django | 8000 | python manage.py runserver 8001 |
| Java Spring Boot | 8080 | --server.port=8081 |
| Tomcat | 8080 | port in conf/server.xml |
| .NET (Kestrel) | 5000 / 5001 | dotnet run --urls http://0.0.0.0:5050 |
| PHP built-in server | any | php -S 0.0.0.0:8001 |
| Go net/http | in code | read the port from an env variable |
| MySQL / PostgreSQL / Redis | 3306 / 5432 / 6379 | the port setting in my.cnf, postgresql.conf, redis.conf |
Real example: the 8080 clash
Jenkins, Apache Tomcat and Spring Boot all use port 8080 by default, and they are often installed together on one practice server. That makes "Port 8080 was already in use" one of the most common errors in DevOps labs. Teams avoid it by writing down a port plan for each server and putting a reverse proxy such as nginx on port 80 or 443 in front of the apps.
Mistakes to avoid
- Running
sudo kill -9on the first PID you see. You may stop your database or SSH. - Closing the terminal but leaving the app running. Check
pm2 list,screen -lsorjobs. - Starting the app as root to use port 80. Use a reverse proxy instead, and keep the app on a high port as a normal user.
- Opening the new port to the world. If you change the port, check the security group and only open what you really need.
Summary table
| Task | Linux | Mac | Windows |
|---|---|---|---|
| Find process | sudo ss -ltnp \| grep :PORT |
lsof -i :PORT |
netstat -ano \| findstr :PORT |
| Details | ps -p PID -o cmd |
ps -p PID |
tasklist /FI "PID eq N" |
| Stop politely | systemctl stop / kill PID |
kill PID |
taskkill /PID N |
| Force | kill -9 PID |
kill -9 PID |
taskkill /PID N /F |
| Docker | docker ps, docker stop |
same | same |
Quick quiz: check what you learned
Which Linux command shows the process listening on a port?
- sudo ss -ltnp
- sudo df -h now
- sudo free -m
- sudo uptime -p
Show answer
A. ss -ltnp lists listening TCP ports with the program and PID.
What should you try before kill -9?
- A normal stop or kill
- Rebooting the server
- Deleting the app folder
- Changing the hostname
Show answer
A. A normal stop lets the program clean up first.
Docker says "port is already allocated". What do you check?
- docker ps for the host port
- docker images for the size
- docker volume ls for data
- docker network prune now
Show answer
A. Another container is usually publishing the same host port.
Which Windows command shows the PID on a port?
- netstat -ano
- ipconfig /all
- tasklist /svc
- systeminfo
Show answer
A. netstat -ano shows connections with their process IDs.
Learn it properly
These pages go deeper, with labs:
Frequently asked questions
What does "address already in use" mean?
Another process is already listening on that IP and port. Only one program can listen on one port at a time.
How do I find what is using port 8080 on Linux?
Run sudo ss -ltnp | grep :8080. The last column shows the program name and its PID.
How do I kill the process on a port in Windows?
Run netstat -ano | findstr :8080 to get the PID, then taskkill /PID 1234 /F.
What is "port is already allocated" in Docker?
Another container or a host program already uses the host port in -p. Run docker ps to find the container and stop it, or use a different host port.
Is kill -9 safe?
It stops the process at once without cleanup, so files or databases may be left half-written. Try a normal kill or systemctl stop first.
Why does the port stay busy after I stop my app?
Sometimes the app is still running in the background (nohup, PM2, an IDE run window), or the socket is in TIME_WAIT for a short time. Check again with ss.