Understanding Port Mapping: The Gateway to Your Applications

Jasai HansdaJasai Hansda
3 min read

When working with web applications, Docker, Kubernetes, or cloud infrastructure, you'll often see things like 8080:80 or 3000:3000 or 443:8443

If you're confused by these numbers and what they do, you're not alone!

Let’s break it down in simple terms so you understand what port mapping is, why it’s used, and how it works.


🚪 First, What Is a Port?

A port is like a doorway to a service on a computer.

Each app or service (like a web server, database, or API) listens on a specific port so your computer knows where to send and receive data.

For example:

PortWhat it usually means
80Web server (HTTP)
443Secure web (HTTPS)
22SSH (remote access)
3306MySQL database
6379Redis
3000, 5000, 8080Dev apps, APIs

🔁 What Is Port Mapping?

Port Mapping means:
➡️ Connecting a port from the outside (host)
➡️ To a port inside the system or app (container, VM, or service)

The format is:

HOST_PORT : CONTAINER_PORT
TermMeaning
Host PortPort exposed to users or browsers
Container PortWhere the app is listening internally

🧠 Real-World Analogy

Imagine a building with a receptionist.

  • People walk in through Door 80

  • The receptionist forwards them to Room 8080 where the real work happens

So, 80:8080 means:

"Let the world in through door 80, but send that traffic to room 8080"


🐳 Docker Example

docker run -p 8080:80 nginx

This tells Docker:

"Expose port 8080 to the outside, but connect it to port 80 inside the container"

So, when you go to: http://localhost:8080

You're actually reaching the container's web server running on port 80.


☁️ Kubernetes Example

In Kubernetes, you define port mapping like this:

ports:
  - port: 80         # Exposed to the internet or service
    targetPort: 8080 # App inside the Pod listens on this

This is the same idea:

  • The service exposes port 80

  • It routes traffic to internal port 8080


🧪 More Examples

Command or SetupMeaning
3000:3000Outside port 3000 → App inside listens on 3000
5000:80Outside port 5000 → Container port 80 (web server)
443:8443HTTPS exposed on 443 → Forwarded to 8443 internally

🛠 Why Use Port Mapping?

  • 🔐 Security: You can hide internal ports and only expose what’s needed.

  • 🧪 Development: Run multiple apps on different external ports.

  • 🧭 Routing: Useful in reverse proxies, load balancers, Docker, and Kubernetes.


⚠️ Common Confusions

MythReality
8080:80 means the app runs on 8080❌ No — the app runs on 80; we access it via 8080
You can use any port freely⚠️ Some ports are reserved (0-1023 require root access)
Internal and external ports must match❌ No — they can be different (and often are)

✅ Summary

TermWhat It Means
Host PortThe port users connect to
Container/Target PortThe port your app listens on internally
80:8080Map outside port 80 to inside port 8080

🔍 Final Thoughts

Port mapping is essential in modern software — from running containers to exposing cloud services.
Once you understand the simple logic of host:container, everything starts to make sense.

Think of it as assigning doors to your app’s rooms and deciding how the outside world reaches the inside.

0
Subscribe to my newsletter

Read articles from Jasai Hansda directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jasai Hansda
Jasai Hansda

Software Engineer (2 years) | In-transition to DevOps. Passionate about building and deploying software efficiently. Eager to leverage my development background in the DevOps and cloud computing world. Open to new opportunities!