Docker port command

Docker command reference


docker portThe command is used to display the container's port mapping information, i.e., how the ports inside the container are mapped to the host's ports.

docker portThe command is very useful for understanding how the container interacts with the host network.

Syntax

docker port CONTAINER [PRIVATE_PORT[/PROTO]]
  • CONTAINER: The name or ID of the container whose port mappings are to be queried.
  • PRIVATE_PORT(Optional): The port number inside the container.
  • PROTO(Optional): Protocol type (tcporudp), default istcp。

View all port mappings of a container:

docker port my_container

Display all port mapping information for the container named my_container.

View the mapping for a specific port:

docker port my_container 80

Display which host port port 80 inside the container named my_container is mapped to.

View the mapping for a specific port and protocol:

docker port my_container 80/tcp

Display which host port TCP port 80 inside the container named my_container is mapped to.

Example

Start a container and map ports:

docker run -d -p 8080:80 --name my_container nginx

This command maps port 80 of the my_container container to port 8080 on the host.

View the container's port mappings:

docker port my_container

Output:

80/tcp -> 0.0.0.0:8080

Display the mapping of container port 80 to host port 8080.

View the mapping for a specific port:

docker port my_container 80

Output:

0.0.0.0:8080

Notes

  • docker portThe command only displays port mapping information and does not show the status of services running inside the container or other information.
  • If the container does not expose any ports, or no port mapping has been performed,docker portThe command will not return any information.

docker portThe command is a tool for viewing container port mappings, helping users understand how container ports are mapped to the host. By using this command, users can conveniently inspect and debug the container's network configuration.


Docker command reference

other extensions