Understanding Port Mapping: The Gateway to Your Applications


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:
Port | What it usually means |
80 | Web server (HTTP) |
443 | Secure web (HTTPS) |
22 | SSH (remote access) |
3306 | MySQL database |
6379 | Redis |
3000, 5000, 8080 | Dev 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
Term | Meaning |
Host Port | Port exposed to users or browsers |
Container Port | Where 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 Setup | Meaning |
3000:3000 | Outside port 3000 → App inside listens on 3000 |
5000:80 | Outside port 5000 → Container port 80 (web server) |
443:8443 | HTTPS 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
Myth | Reality |
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
Term | What It Means |
Host Port | The port users connect to |
Container/Target Port | The port your app listens on internally |
80:8080 | Map 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.
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!