How to Use the Docker Port Command
The docker port command is used to display the public-facing port(s) of a container. It shows the mapping between the container’s internal port and the corresponding host port.
To use the docker port command, you can follow these steps:
Make sure you have Docker installed and running on your system.
Open a terminal or command prompt.
To view the port mappings of a running container, you need to know the container’s ID or name. You can find the ID or name of the container by using the docker ps command:
docker ps
This will display a list of running containers along with their details.
Once you have the container ID or name, you can use the docker port command followed by the container ID or name:
docker port {{container-id-or-name}}
Replace {{container-id-or-name}} with the actual ID or name of the container you want to inspect.
After running the docker port command, Docker will display the mapping between the container’s internal port and the corresponding host port.
The output may look something like this:
80/tcp -> 0.0.0.0:32768
This indicates that the container’s internal port 80 is mapped to the host port 32768.
If the container has multiple exposed ports, the docker port command will display the mapping for each port.
Please note that the docker port command only works with running containers. It shows the mapping between the container’s internal port and the corresponding host port, which allows you to access services running inside the container from your host machine.
