How to check which ports are in use?

QuestionsQuestions8 SkillsProDec, 24 2025
0190

That's a very practical question! Since you are working in a Linux environment, there are a few ways to check which ports are currently occupied.

1. Check ports used by Docker

To see which ports your Docker containers are using, the most common way is:

docker ps

In the PORTS column, you will see something like 0.0.0.0:8080->80/tcp. This tells you that port 8080 on your host is currently busy.

2. Check all ports on the system

If you want to see every port in use (including those used by processes outside of Docker), you can use the ss command (which stands for socket statistics):

sudo ss -tuln

Breakdown of the flags:

  • -t: Show TCP ports.
  • -u: Show UDP ports.
  • -l: Show Listening sockets.
  • -n: Show Numeric port numbers (instead of names like "http").

3. Find which specific process is using a port

If you get an error saying "Port already in use" and want to find the "culprit," use lsof:

sudo lsof -i :8080

This will show you the name of the command and the PID (Process ID) using port 8080.

4. Summary for your current Lab

In your current lab setup, since you just ran:
docker run -d -p 8080:80 --name my-nginx-container my-nginx

If you run docker ps, you will see that 8080 is active. If you tried to start another container using -p 8080:80, Docker would give you an error because port 8080 is already claimed!

Would you like to try running a second container on a different port to see how they coexist?

0 Comments

no data
Be the first to share your comment!