You can map ports in Docker using the -p option with the docker run command. The syntax for mapping ports is as follows:
docker run -p [host_port]:[container_port] [image_name]
Here’s a breakdown of the parameters:
host_port: The port on your host machine that you want to map.container_port: The port inside the container that your application is listening on.image_name: The name of the Docker image you want to run.
Example
To run a web application in a container that listens on port 80 and map it to port 8080 on your host, you would use:
docker run -p 8080:80 my_web_app
This command allows you to access the application running in the container via http://localhost:8080.
