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 port number you need to map the port number of the container with the port number of the docker host.
Implementation
In the implementation, we are going to download a Jenkins container from the docker hub and map the Jenkins container port number with the docker host port number.
Step 1:
Sign-up to your docker hub repository.
Sign-up in docker hub
Step 2:
Search for the Jenkins image and use the docker pull command to download the Jenkins image on your local server.
Step 3:
Download Jenkins’s image using the below command:
sudo docker pull jenkins
Step 4:
To see the ports exposed by the Jenkins container type docker inspect command.
docker inspect Container/image
Step 5:
In this step, we run Jenkins and map the port by changing the docker run command by adding the p option which specifies the port mapping.
sudo docker run -p 8080:8080 50000:500000 jenkins
On the left-hand side, it is the Docker host port number and on the right-hand side Docker container number.
These are all the steps required to map the port number of the container to the port number of the docker host.