Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker port Command

Docker port Command

Docker Command ReferenceDocker Command Reference


docker port The command is used to display a container's port mapping information, that is, how ports inside the container map to ports on the host.

docker port The command is very useful for understanding how a container interacts with the host network.

Syntax

docker port CONTAINER [PRIVATE_PORT[/PROTO]]

View all port mappings of a container:



docker port my_container

Display all port mapping information of the container named my_container.

View the mapping of a specific port:



docker port my_container 80

Show which host port the internal port 80 of the container named my_container is mapped to.

View the mapping of a specific port and protocol:



docker port my_container 80/tcp

Show which host port the internal TCP port 80 of 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 a container's port mappings:



docker port my_container

Output:



80/tcp -> 0.0.0.0:8080

Show that the container's port 80 is mapped to port 8080 on the host.

View the mapping of a specific port:



docker port my_container 80

Output:



0.0.0.0:8080

Notes

docker port The command is a tool for viewing container port mappings, helping users understand how a container's ports map to the host. By using this command, users can easily check and debug a container's network configuration.


Docker Command ReferenceDocker Command Reference