How to find a free TCP port for testing PubSub+ with Docker
To run a network server like Solace PubSub+, you must configure it to use ports that are not currently in use. However, ports 80 and 8080 are often used by other applications. This means that you need to find a free TCP port in order to test PubSub+ using Docker. Before you can find out which port is free, you have to find out what ports are already in use. The good news is there are tools that can help you identify them. I’ve listed some of them below.
Windows
Netstat
Command: netstat -a -n -p tcp | findstr LISTENING
Note: Netstat produces so many results that you need to filter them with findstr.
netstat
-a
- Displays all active TCP connections and the TCP and UDP ports on which the computer is listening.
-n
- To see port numbers instead of port names like "http" or "epmap"
-p (protocol)
- Shows only the ports that are using this protocol, in this example, tcp
For more info:
- Run
netstat -h
- Read Microsoft Docs
- Run
|
- That’s a pipe symbol, not a capital i or a lowercase L.
- This symbol “pipes” output from the previous command (netstat) to the next command (findstr)
findstr
findstr
is a filter tool. It selects the lines with “LISTENING” in them and ignores other lines.- For more info:
- Run
help findstr
- Read Microsoft Docs
- Run
TcpView by Sysinternals
This is a GUI tool for looking at TCP information on Windows.
- Download it from Sysinternals/Microsoft
- Read Microsoft Docs
- To see port numbers instead of port names like "http" or "epmap", click on the “A” in the toolbar at the top left of the window.
Mac
Lsof
Command: lsof -i -P
- Do not combine the two parameters, like “-iP”, to avoid misinterpretation by lsof.
- Use
sudo
to include all the ports owned by system processes - For more details, run
man lsof
Linux
ss
Command: ss -ltn
-l
- listening ports only
-t
- TCP ports only
-n
- See port numbers, instead of port names like "http" or "epmap"
- For more details, run
man ss