Docker & DevOps Tool

Docker Port Mapping Generator

Build Docker port mapping rules for docker run and Compose without memorising the syntax. Set host and container ports, pick TCP or UDP, bind to a specific IP, and catch duplicate host ports before you start a single container.

Every mapping is written host:containerOutputs docker run flags and Compose YAMLFlags duplicate host ports in your list

How-to

How to Map Docker Compose Ports in 3 Simple Steps

Add a mapping, choose how it's published, then copy the result. Three steps.

  1. 01

    Enter host and container ports

    Start with the container port, which is whatever your app listens on inside the image. Then pick the host port you want to open from your browser or client. If the app listens on 80 and you want to visit localhost:8080, the host port is 8080 and the container port is 80. Leave the host port blank and Docker assigns a random one.

    Enter Docker host port and container port for a host:container mapping
  2. 02

    Choose protocol and bind address

    TCP is the default. Switch to UDP for DNS, syslog or game servers. Add 127.0.0.1 as the host IP if the service should only be reachable from your own machine. With no IP, Docker listens on every interface. Getting this part of Docker port binding right is the difference between a private dev database and an open one.

    Choose TCP or UDP protocol and an optional bind address for Docker port publishing
  3. 03

    Copy or check

    Copy the docker run flags or the Compose block. The table marks any rows that share a host port and protocol, so you can fix a Docker port conflict here instead of reading about it in a terminal later.

    Copy docker run -p flags or Compose ports YAML and review duplicate host port conflicts

Features

What this Docker port mapping generator includes

  • 01

    docker run -p output

    Every row becomes a -p flag, including the IP prefix and the /udp suffix when you need them.

  • 02

    Docker Compose ports YAML

    Switch between the short "8080:80" string and the long form with target, published and protocol. It's the quickest way to get Docker Compose port mapping right when you can't remember which key goes where. Values are quoted so YAML never misreads something like 22:22 as a number, which keeps the Docker Compose map ports syntax safe.

  • 03

    Duplicate host-port detection

    Two mappings can't share the same host port, protocol and IP. The table flags the clash straight away.

  • 04

    Bind IP support

    Restrict a port to localhost, or to one network interface, with a single field.

  • 05

    Ranges and random ports

    Map a block like 8000-8010 in one go, or leave the host side empty and let Docker choose.

Formats

Supported Docker port mapping formats

Pick a tab to see how each format is written and when to use it. Docker container port mapping comes in a handful of shapes, and the samples assume an app listening on port 80 inside the container.

Host:Container

Publishes container port 80 on host port 8080 over TCP.

-p 8080:80

Workflow

Docker port mapping workflow in your browser

Here's the routine from first idea to running service. Most of it happens in this tab, and the last check happens in your terminal.

  • Find the container port

    Check the Dockerfile, the image docs or your app config for the port the service listens on inside the container.

  • Pick a free host port

    Run ss -tulpn | grep 8080 on Linux, lsof -i :8080 on macOS, or netstat -ano on Windows. This tool can't act as a Docker port availability checker for your machine, because a browser tab has no view of your host's sockets, but those commands do the job in seconds.

  • Add the mapping

    Enter both ports, choose TCP or UDP, and add a bind IP if needed.

  • Review the table

    Look for duplicate host ports and for bindings you didn't mean to leave open to every interface.

  • Copy and verify

    Paste the flags into your run command, or the block into your Docker Compose port mapping section, then confirm with docker ps or docker port <container>.

Docker port mapping workflow with compose editor, port table, and export output in the browser
Build mappings in the tab, scan the table for conflicts, then copy run flags or Compose YAML.

Audience

Who Docker port mapping is for

Anyone who runs containers on a laptop, a server or a CI runner and needs the ports to line up.

  • Backend developers

    Running an API, Postgres and Redis locally means juggling Docker container ports so nothing collides with the Postgres already installed on your laptop.

  • DevOps and platform engineers

    Agree on one Docker Compose map ports convention across repositories, and catch stray 0.0.0.0 bindings during review.

  • QA and test engineers

    Run several copies of the same service side by side on different host ports, then tear them all down again.

  • Students and self-hosters

    Learning Docker, or hosting Nginx, Pi-hole or Home Assistant at home? Ports are one piece of your wider Docker network configuration, and usually the first piece that bites.

Use cases

What you can finish faster

Run commands, Compose snippets and port fixes are all one form away.

  • Outcome

    Local dev stacks

    Web on 3000, API on 8080, Postgres on 5433 because your laptop already owns 5432. Build all three mappings and copy them together. This is Docker container port mapping at its most practical.

  • Outcome

    Fixing "port is already allocated"

    When Docker refuses to start a container, only the host side needs to change. Keep the container port and move the host port.

  • Outcome

    Compose files for teammates

    Paste a tidy block of Docker Compose ports into the repo instead of a chat message that says "it's 8080, I think."

  • Outcome

    Reverse proxy setups

    Keep Docker port forwarding limited to your proxy on 80 and 443, and leave every other service unpublished so the proxy reaches them over the Docker network. Run docker inspect output through the JSON Formatter when you want proof of what's actually published.

Limits

Firewalls, port conflicts, and what port mapping won't do

Publishing a port is a networking rule, not a security feature.

  • Published ports can bypass your firewall

    Docker adds its own iptables rules, so a ufw rule may not block a published port the way you'd expect. Bind to 127.0.0.1 unless you really mean to open it to the network.

  • One owner per host port

    Only one process can hold a given host port, protocol and IP at a time. When you see "Bind for 0.0.0.0:8080 failed", something already owns it, so change the left-hand number.

  • Containers can communicate without publishing

    Containers can communicate directly with one another without requiring their images to be published to a registry. On the same user-defined network, services reach each other by name on the container port. Mixing that up with host publishing is a frequent source of Docker port configuration mistakes. Docker Compose port mapping follows the same rule: it publishes to the host and nothing more.

  • Host networking and Docker Desktop

    With --network host on Linux, -p is ignored because the container shares the host's network. On Docker Desktop, localhost forwarding passes through a VM, so behaviour can differ from a Linux server.

Why this tool

Why use this Docker port mapping generator

Docker port mapping cheat sheets are everywhere. Few give you CLI flags, Compose YAML and a duplicate check from the same input.

  • Formats

    One mapping, every format

    Enter it once and copy it as docker run flags, short Compose syntax or long Compose syntax.

  • Conflicts

    Conflicts caught before you run

    Duplicate host ports show up in the table, not as a failed container start.

  • Defaults

    Safer defaults in view

    The bind IP field is always on screen, so exposing a service to every interface is a choice you make rather than something you miss.

  • Privacy

    Nothing leaves your browser

    No sign-up, no install, no upload. The ports and IPs you type stay in the tab.

  • CLI + Compose

    Built for CLI and Compose users alike

    Docker container port mapping reads the same in both worlds here, and the Docker Compose map ports syntax stays consistent with the -p flags.

  • Copy

    Copy-ready snippets

    Grab the format you need for a Dockerfile workflow or Compose file without retyping host and container ports.

100%

Runs in your browser

3

Output formats ready to copy

0 bytes

Uploaded anywhere

Comparison

Docker port mapping generator vs popular alternatives

Most people compare options by reading docs, typing by hand or poking at a running container. Here's how those approaches stack up.

Capability

This docker port mapping generator

Docs / cheat sheets
Typing by hand
CLI commands
  • docker run -p flags
    Yes
    Examples only
    Yes
    —
  • Docker Compose port mapping YAML
    Yes
    Examples only
    Yes
    —
  • Duplicate host ports in your list
    Yes
    —
    —
    —
  • Live host port usage
    —
    —
    —
    Yes
  • Works with no install
    Yes
    Yes
    Yes
    Needs Docker/shell

Want both? Generate the mapping here, then confirm on your machine with the commands above.

Try Docker Port Mapping Generator

Privacy

Everything you enter stays in this tab

Everything you enter stays in this tab. Nothing is uploaded or stored.

Docker port mapping questions

Docker listens on a host port and forwards traffic to the container's port. You describe it as host:container, either with -p on the command line or under ports: in Compose. With no bind IP, it listens on all interfaces.

Open to freelance & collaborationIndia

Start a project

Let's Build Something Great Together

Have a project, product idea or development challenge? Let's discuss how I can help turn it into a reliable, scalable web application.

~/hire-jay

$

Usually replies within 24 hours

What brings you here?