Port Mapping means connecting a service port inside the container to a port on the host machine. The web server inside the container runs on port 80, but to reach it from your host browser, you need to publish a host port.
# Syntax
# docker run -p HOST_PORT:CONTAINER_PORT image_name
# Example: open Nginx through localhost:8080
docker run --name nginx-port-demo -d -p 8080:80 nginx8080:80 — the left side, 8080, is the port on your computer, and the right side, 80, is the Nginx port inside the container.
You'll see the Nginx page at http://localhost:8080.Info
A host port can't be used by more than one container at the same time. If you see a 'port already allocated' error, change the port or stop the old container.