Why We Use Port Mapping?
The network services of a container are made accessible to the host or external network through port mapping in Docker. Docker containers can only communicate with other containers on the same Docker network and run by default in isolation from the host and external networks. By publishing a container’s network service to the host or external network through port mapping, you can make it reachable from other networked devices.
When running a Docker container, you can map a port on the container to a port on the host or external network using the -p or —publish options. If you use the below command it will publish nginx, for instance, would publish port 80 from the container to port 8080 on the host or external network.
docker run -p 8080:80
How to Map Ports in Docker?
In docker, all the application in the container runs on particular ports when you run a container. If you want to access the particular application with the help of a port number you need to map the port number of the container with the port number of the docker host.
Contact Us