Docker Port Mappings

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:

-p <Host_Port>:<Container_Port>

If you want to map TCP port 80 inside the container to port 8080 on the host then you would issue:

-p 8080:80

Now that it done, let’s go to Docker Hub and look up Jenkins.

Screenshot from the Docker Port Mapping walkthrough at step 1; the adjacent article text explains that 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

Screenshot from the Docker Port Mapping walkthrough at step 2; the adjacent article text explains that $ docker run -p 8080:8080 jenkins.

$ 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

Screenshot from the Docker Port Mapping walkthrough at step 3; the adjacent article text explains that 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

Jenkins Getting Started page prompting for the initial administrator password on port 8080.

Success!

Screenshot from the Docker Port Mapping walkthrough at step 5, showing Install suggested; the adjacent article text explains that the walkthrough can begin installing plug-ins.

Now we can begin installing plug-ins.

Summary:
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.

Keep exploring

Choose your next step

Continue with the path that best matches the architecture or operating challenge in front of you.

Leave a Reply

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading