Reputation: 35424
When running a new container, we specify a port RUN_PORT:EXPOSED_PORT
to map with the host machine. This will fail if RUN_PORT
is already used.
So my question is how to list all the mapped port - so that we can pick up the port number out of the list.
p.s.
I'm using Ubuntu 16.04
Upvotes: 0
Views: 1872
Reputation: 264851
Listing all tcp ports being used (for listening) can be seen with:
netstat -lnt
Looking up what is using a single port can be done with a netstat and grep, or if you have lsof installed:
sudo lsof -i :80 # shows the process using port 80
Starting a docker container on a random available port mapped to port 80 inside the container:
docker run -p 80 -n container_name your_container
Looking up what random port docker used in the above command on the host (this includes what IP interfaces it's attached to, or 0.0.0.0 for all interfaces, which is the default):
docker port container_name 80
Upvotes: 1
Reputation: 2658
Do the following command
sudo netstat -tlnp | grep ":RUN_PORT"
Replace RUN_PORT with the actual port to see which application is blocking it.
Upvotes: 2