Skip to main content

whichport - how to become a process detective

·91 words·1 min
Maja Milinkovic
Author
Maja Milinkovic
Machine learning / platform engineer with experience building, deploying, and scaling ML systems from POC to production.
Cannot start container...
Port already in use: 5001

Look familiar?

If you’re anything like me, you frequently have multiple docker containers, ports forwarded, or just generally too many apps running on different ports.

Luckily, I have the solution. I call it whichport.

It’s a simple bash function. Just add the following to your ~/.bash_profile:

# find which process is running on a port, ex: `whichport 4200`
whichport() {
        if [ -z "$1" ]; then
                echo "no argument supplied (enter port to check)"
                return 1
        fi
        lsof -i:$1 | grep LISTEN;
}