liveBook · Manning

Port number

As explained in Road to Kubernetes

A port is a numbered network endpoint through which a host or container accepts or sends traffic for an application or service.

A port number identifies a network endpoint where an application or service accepts traffic. Changing the port changes the URL used to reach a locally running application. section 2.2.2 section 5.1.2

Web applications commonly choose a default port but can read one from an environment variable or command-line option. Express.js defaults to 3000, while FastAPI can run through Uvicorn on a specified port. section 2.2.2 section 2.1.2

Containerized applications add a second port to the configuration:

  • The container port is the port the application expects internally. section 5.1.2
  • The local port is the host-side port used in a browser or other client. section 5.1.2
  • Docker maps them with -p <localPort>:<containerPort>; for example, localhost:8080 reaches NGINX on container port 80. section 5.1.2

Moving an Express.js server

Run the default server with node main.js and visit http://127.0.0.1:3000. Stop it, then run PORT=3011 node main.js on macOS or Linux, or set PORT=3011 && node main.js on Windows. The server is now available at port 3011; the old port no longer responds. section 2.2.2

Listing 2.20 Running the Express.js web server on a new port
# macOs or Linux
PORT=3011 node main.js

# Windows
set PORT=3011 && node main.js

Compare the macOS/Linux and Windows commands for starting Express.js on port 3011. section 2.2.2

How Road to Kubernetes covers it

How deep it goes
Explains defaults, environment and command-line overrides, and host-to-container mappings without descending into networking internals.
Examples
Uses Express.js on ports 3000 and 3011, FastAPI on 8011, and Docker mappings from 8080 to NGINX port 80.
What you can do after
Operate local applications and containers by selecting reachable ports and applying host-to-container mappings.
How it connects
Connects ports with HTTP applications, environment variables, Docker containers, Express.js, FastAPI, Uvicorn, and NGINX.

Also explained in

Compare how 7 books explain port number →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.