Docker port Command
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]]
CONTAINER: The name or ID of the container whose port mappings you want to query.PRIVATE_PORT(Optional): The port number inside the container.PROTO(Optional): The protocol type (tcporudp), the default istcp。
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 portThe command only displays port mapping information; it 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 is configured,
docker portthe command will not return any information.
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 Reference