Docker

How to List Exposed Port of All Containers?

Docker containers are used to containerize software and projects. These containers encapsulate project dependencies and program code. You can use these containers to build, run and manage projects. In most cases, the Docker containers are executed on some specific ports to deploy projects and programs. Therefore, users are required to specify the port on which the Docker container will host and execute the containerized program.

This blog will illustrate how to list exposed ports of all containers.

How to List Exposed Port of All Containers?

To list exposed ports of all containers, users can simply utilize the “docker ps -a” command. This command will show information about Docker containers and exposed ports.

To view the exposed ports of containers, check out the mentioned examples.

Example 1: Show Exposed Port of a Specific Container

To view the exposed port of specific containers, utilize the “docker port <container-name>” command. However, users can also use the container id to view the container mapping port:

> docker port serene_engelbart

Alternatively, you can view the mapping information of a specific port in a specified container using provided command:

> docker port serene_engelbart 8080/tcp

Example 2: List Exposed Port of All Containers

In order to list down the exposed ports of all Docker containers, utilize the “docker ps -a” command:

> docker ps -a --format "table {{.Names}}\t{{.Ports}}"

Here:

  • –format” is used to specify the format of the listed detail. For instance, we have listed down container names and exposed ports.
  • -a” is utilized to list exposed ports of all containers:

Bonus Tip: How to Assign Exposing Port to Container?

Docker users can assign the exposing port to Docker containers while creating a new container. To create a new container, utilize the “docker create” command:

> docker create --name base-container -p 8080:8080 dockerimage

In the above command:

  • –name” option is used to specify the name of the container.
  • -p” is used to specify the exposing port where the container will execute.
  • dockerimage” is an image that provides a template to build a Docker container:

We have discussed how to list exposed ports of all Docker containers.

Conclusion

To view the exposed port of the container, users can utilize the “docker port <container-name>” command. However, in order to list exposed ports of all containers, simply use the “docker ps -a” command. You can also view the specific port of the container using the “docker port <container-name> <port>” command. This write-up has demonstrated how to list exposed ports of all containers.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.