Introduction
A container runs in its own isolated network and its ports are not accessible from your computer by default. The -p flag maps a port on your host machine to a port inside the container so you can reach the app running inside it.
When you run a web server in a container and want to open it in your browser on your computer.
When you run a database container and want your app on the host to connect to it.
When you need to expose multiple services from the same container on different host ports.
When you want to test a containerized API from tools like Postman or curl on your machine.
When you run multiple containers with the same internal port and need to map each to a different host port.