Free a port that is already in use on Mac
A DockRun workflow that finds what is listening on a port such as 3000 and stops it, so "address already in use" goes away.
The button needs DockRun 0.1.19 or later. On an older version, download the file, then use Settings > Restore or Import… in DockRun.
Runs in DockRun Free, which holds 2 workflows.
What it does
- Finds every process listening on the port you chose (3000 unless you change it).
- Asks each one to stop, and names it so you know what was closed.
- Forces only the ones that ignore the request, then confirms the port is free.
What you can change
port- The port to free. Starts as:3000
The steps
Read the script below before you add it. It is everything this workflow runs.
- 1. Stop what is using the portRuns this zsh script · Arguments: {{var.port}} · Time limit: 20 seconds
# Stops whatever is listening on a TCP port (default 3000), so your dev server can start. port="${1:-3000}" [[ "$port" == <1-65535> ]] || { echo "Not a port number: $port" >&2; exit 1 } listening() { lsof -nP -tiTCP:"$port" -sTCP:LISTEN 2>/dev/null } pids=($(listening)) (( ${#pids} )) || { echo "Nothing is listening on port $port."; exit 0 } for pid in $pids; do echo "Stopping $(ps -p "$pid" -o comm= | sed 's|.*/||') (pid $pid)" kill "$pid" 2>/dev/null done sleep 1 for pid in $(listening); do kill -9 "$pid" 2>/dev/null && echo "Had to force pid $pid"; done [ -z "$(listening)" ] && echo "Port $port is free." || { echo "Port $port is still in use (owned by another user?)." >&2; exit 1 }
After you add it
- DockRun shows what is in the file and asks before adding it. The workflow arrives turned off.
- Open it, read the steps, then turn on the On switch.
- Press Run. DockRun asks before a script runs; tick "Don't ask again for this exact step" once you trust it.
Good to know
It can only stop your own processes. A port held by another user or by the system is reported, not forced.
Last tested: 2026-11-12 · All workflows →