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;
}