Docker Port Mapping

docker run -itd -p :

kindly explain what is a host port and how to choose one.
Also what does the host port represent, is it the port number of an application running on the host machine that helps in accessing the App from outside ?

Yes the host port is the port number on your host machine that you map to a port inside your Docker container. When you specify -p <host_port>:<container_port>, you are telling Docker to forward traffic from the host port to the container port.

Ensure the chosen host port is not already in use by another application on the host machine. Use well-known ports for specific services if they are not already in use (e.g., 80 for web servers, 3306 for MySQL etc).

However, you are free to use any port you wish so long as it is not in use.

1 Like

Thank you for the reply and beautiful explanation , Sir