Skip to main content
Back to Dev generators

Dev

Random Port & Service Generator

Choosing non-conflicting port numbers for a microservices stack, Docker Compose file, or Kubernetes cluster is tedious — getting it wrong means a bind conflict that blocks a service from starting. A random port and service generator produces deduplicated port assignments with service labels across three standard IANA ranges. Three inputs control the output. Count sets the batch size (1–30); the generator deduplicates across the run so each port appears at most once. Port Range selects well-known (canonical ports like 22, 80, 443, 587), registered (application services like MySQL 3306, PostgreSQL 5432, Redis 6379), or ephemeral (common dev server ports like 3000, 5173, 8080). Any draws from all three pools. Output Format determines the shape: labeled pairs port numbers with service names, envvar produces PORT=5432 lines for a .env file, and portonly returns bare numbers for scripts.

Read the complete guide — 4 min read

How to use

  1. Choose your options above
  2. Click Generate
  3. Copy your result

Detailed instructions

  1. Set the 'How Many' field to the number of port assignments you need for your project.
  2. Choose a Port Range: well-known for protocol reference, registered for app services, or ephemeral for high-range assignments.
  3. Select your Output Format — labeled for readable docs and diagrams, or env-var format for direct use in .env files.
  4. Click Generate to produce a deduplicated list of port-service pairs from your chosen range.
  5. Copy the output and paste it into your config file, diagram tool, or teaching material.

Use Cases

  • Generating PORT_ env vars for a Node.js microservices stack before writing any config files
  • Assigning unique host-side ports across services in a docker-compose.yml to prevent bind conflicts
  • Creating labeled port-to-service maps for network architecture diagrams in Figma or Lucidchart
  • Producing realistic port assignments for firewall rule exercises in a networking or DevOps course
  • Allocating ports across 8+ services in a local Kubernetes cluster using Minikube or kind

Tips

  • Use the registered range with env-var output when scaffolding a new docker-compose.yml — paste results straight into the ports section.
  • Generate well-known ports when building a networking lesson; the labeled format shows students which services live at which canonical ports.
  • If a generated port conflicts with one already in use, regenerate the full set rather than swapping one port manually — you may introduce a new conflict.
  • Cross-check generated ports against your machine's bound ports with 'lsof -i -P -n | grep LISTEN' on macOS/Linux before committing them to config.
  • For microservice projects, generate a larger batch than you need (e.g. 12 for 8 services) and keep the spares as documented reserves for future components.
  • Ephemeral range ports work well for short-lived test servers in CI pipelines where port persistence across runs is not required.

FAQ

what is the difference between well-known, registered, and ephemeral port ranges

Well-known ports (0–1023) are reserved by IANA for core protocols like HTTP (80) and SSH (22) and typically require root to bind. Registered ports (1024–49151) cover named application services like MySQL (3306) and PostgreSQL (5432). The ephemeral selection here is a curated list of common dev server ports like React (3000), Django (8000), and Vite (5173) — not the OS ephemeral range.

can two Docker containers use the same host port at the same time

No — only one process can bind a given TCP or UDP port on a host interface at a time. A second container mapping to the same host port will fail to start with an 'address already in use' error. Generate a unique batch here, assign one port per container, and paste them into your docker-compose.yml ports section.

what does the env var output format look like and how do I use it

The envvar format produces lines like POSTGRESQL_PORT=5432 or REACT_DEV_PORT=3000, ready to paste into a .env file or shell export block. Service names are uppercased and non-alphanumeric characters are replaced with underscores. This skips the manual reformat step when moving from a labeled port list to actual config files.

does the generator guarantee no duplicate ports in the output

Yes. The generator tracks used ports within each run and retries when a collision occurs. If the pool for a selected range is exhausted, it falls back to a random port in the 10,000–60,000 range. For the well-known and registered ranges, generating more ports than the pool contains may produce some fallback values.

You might also like

Popular tools from other categories that share themes with this one.

Try these next

More free tools from other corners of the catalog, picked by shared themes.