Sonar: Finally Know What's Running on Your Localhost Ports
TL;DR: Sonar is a CLI that shows everything listening on localhost—ports, processes, Docker containers—and lets you kill, inspect, or tail logs with simple commands. No more
lsof | grepgymnastics. Install:curl -sfL https://raw.githubusercontent.com/raskrebs/sonar/main/install.sh | bash
Every developer has memorized their port numbers. 3000 is Next.js. 5432 is Postgres. 8080 is the API. And then one day you run npm run dev and get “port already in use”—and now you’re spelunking through lsof -iTCP -sTCP:LISTEN | grep ... trying to figure out if it’s a zombie Docker container or an orphaned dev server from a branch you forgot to close.
Sonar fixes this. One command shows everything. One command kills it.
What Does Sonar Do?
Sonar shows all services listening on localhost ports in a clean table format:
$ sonar list
PORT PROCESS CONTAINER IMAGE URL
1780 proxy my-app-proxy-1 traefik:3.0 http://localhost:1780
3000 next-server http://localhost:3000
5432 db my-app-db-1 postgres:17 http://localhost:5432
6873 frontend my-app-frontend-1 frontend:latest http://localhost:6873
9700 backend my-app-backend-1 backend:latest http://localhost:9700
5 ports (4 docker, 1 user)
It knows the difference between Docker containers and native processes. It shows Compose project names. It gives you clickable URLs.
How Do I Install Sonar?
One-liner install:
curl -sfL https://raw.githubusercontent.com/raskrebs/sonar/main/install.sh | bash
This downloads the binary to ~/.local/bin. Restart your terminal or source ~/.zshrc.
If you prefer Go:
go install github.com/raskrebs/sonar@latest
Shell completions (tab-complete port numbers):
sonar completion zsh > "${fpath[1]}/_sonar" # zsh
sonar completion bash > /etc/bash_completion.d/sonar # bash
sonar completion fish | source # fish
How Do I Kill a Process on a Port?
sonar kill 3000 # SIGTERM
sonar kill 3000 -f # SIGKILL (force)
For Docker containers, Sonar automatically uses docker stop instead of sending signals.
Kill multiple at once:
sonar kill-all --filter docker # stop all Docker containers
sonar kill-all --project my-app # stop a Compose project
sonar kill-all --filter user -y # kill all user processes, skip confirmation
What Features Does Sonar Offer?
Inspect a port:
sonar info 3000
Shows full command, user, bind address, CPU/memory/threads, uptime, health check result, and Docker details.
View logs:
sonar logs 3000
For Docker containers, runs docker logs -f. For native processes, discovers log files via lsof and tails them.
Watch for changes:
sonar watch # poll every 2s, show diffs
sonar watch --stats # live resource stats
sonar watch --notify # desktop notifications when ports go up/down
Wait for ports (perfect for scripts):
sonar wait 5432 --timeout 30s # block until ready
sonar wait 5432 --http # wait for HTTP 200
sonar wait 5432 3000 6379 # wait for multiple
# Example: run migrations after services are up
docker compose up -d
sonar wait 5432 3000 --timeout 60s && npm run migrate
Dependency graph:
sonar graph # show which services talk to each other
sonar graph --dot # Graphviz DOT format
Profiles (save expected ports):
sonar profile create my-app # snapshot current ports
sonar up my-app # check if expected ports are running
sonar down my-app # stop all ports in the profile
Find free ports:
sonar next # first free port from 3000
sonar next 8000 # first free port from 8000
sonar next -n 3 # 3 consecutive free ports
Port forwarding:
sonar map 6873 3002 # proxy 6873 → also available on 3002
How Does Sonar Compare to Alternatives?
| Feature | lsof | grep | Sonar | Portless |
|---|---|---|---|
| List ports | ✅ Manual parsing | ✅ Clean table | N/A |
| Docker awareness | ❌ | ✅ Container names, images | N/A |
| Kill by port | ❌ Multi-step | ✅ sonar kill 3000 | N/A |
| View logs | ❌ | ✅ sonar logs | N/A |
| Wait for ready | ❌ | ✅ sonar wait | N/A |
| Avoid port conflicts | ❌ | ❌ | ✅ Named URLs |
Sonar + Portless is actually a great combo:
- Portless eliminates port numbers with named
.localhostURLs - Sonar helps when you need to see what’s actually running
When Should I Use Sonar?
- “Port already in use” — see what’s hogging it, kill it
- Docker Compose debugging — which containers are actually running?
- CI/CD scripts —
sonar waituntil services are ready before running tests - Resource monitoring —
sonar list --statsfor CPU/memory per service - Multi-project development — profiles let you snapshot and restore port states
Frequently Asked Questions
What is Sonar CLI?
Sonar is a command-line tool for inspecting and managing services on localhost ports. It shows processes, Docker containers, resource usage, and lets you kill, log, or inspect any service by port number.
How do I install Sonar?
Run curl -sfL https://raw.githubusercontent.com/raskrebs/sonar/main/install.sh | bash or go install github.com/raskrebs/sonar@latest.
Does Sonar work with Docker?
Yes. Sonar detects Docker containers, shows container names, Compose project names, and images. Killing a Docker port runs docker stop automatically.
Can I use Sonar in CI/CD pipelines?
Yes. sonar wait 5432 --timeout 60s blocks until a port is ready—perfect for waiting on database containers before running migrations or tests.
Does Sonar support remote machines?
Yes. Use sonar list --host user@server or sonar watch --host user@server to scan via SSH.
What platforms does Sonar support?
macOS (uses lsof) and Linux (uses ss).
Is there a GUI?
The macOS tray app (sonar tray) shows live port stats in your menu bar. It’s included in the install script.
What license is Sonar released under?
MIT license—free for any use.
Links: