I think Docker has the best explination of port mapping, “By default, when you create a container, it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container’s network, use the –publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host.”
Link to Container Networking:
Easiest example I can give:
If you want to map TCP port 80 inside the container to port 8080 on the host then you would issue:
Now that it done, let’s go to Docker Hub and look up Jenkins.
As you can see from the above Jenkins has a port requirement of 8080:8080
$ docker run -p 8080:8080 jenkins
Because I have never downloaded Jenkins, docker is going to have to go pull the image from Docker Hub
Now we can see that “Jenkins is fully up and running” and it gave the super-secret admin password we will need to log in
Let’s see if we can hit it from port 8080
Now we can begin installing plug-ins.
As you can see port mapping in Docker is easy and most apps publish their port requirements. As always, I hope y’all found this useful.