For easy development, shipping and running of applications we use an open source platform "Docker".

Docker uses "Containers" to avoid external affect on the development environment. Containers does not publish any of its ports to the outside world.

Sometimes we need the ports outside the Docker Container.

The below code is used to get list of port of all containers.

docker container ls 


The above command shows only the running containers in the localhost.

​docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a 

Outputs:

CONTAINER ID   NAMES             PORTS
b3ded776ddc4   container1        0.0.0.0:31005->80/tcp, :::31005->80/tcp
e3f26ef31f90   container2        0.0.0.0:31004->80/tcp, :::31004->80/tcp
e215cc9c2be9   container3        0.0.0.0:31003->80/tcp, :::31003->80/tcp
The above command shows all the running and non-running containers in the localhost.