List docker containers with IP and port
If you need to find conflicting ports or just want to know which ports are being used by your docker containers, you can list all running docker containers with their IP and port.
To list all running docker containers with their Network and port, you can use the following command:
sudo docker ps --format "{{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Networks}}"
If you want to display the output in a table format, you can use the following command:
sudo docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Networks}}"
To display IP address use the following:
sudo docker ps -q | xargs sudo docker inspect --format '{{.Name}} | {{range $net,$conf := .NetworkSettings.Networks}}{{$net}}:{{$conf.IPAddress}} {{end}}| {{range $p,$conf := .NetworkSettings.Ports}}{{$p}}->{{range $conf}}{{.HostIp}}:{{.HostPort}} {{end}}{{end}}'