Related Articles

Related Articles

How to Map Ports in Docker?
  • Last Updated : 16 Oct, 2020

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.

docker sign in page

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.

docker console



Step 3:

Download Jenkins’s image using the below command:

sudo docker pull jenkins

downloading jenkins

Step 4:

To see the ports exposed by the Jenkins container type docker inspect command.

docker inspect Continer/image

container

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.

mapping port

These are all the steps required to map the port number of the container to the port number of the docker host. 

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :