Appearance

Networking before Kubernetes

Trace a web request from the name you type to the process that answers it.

What you will understand

  • Distinguish an interface, its IP address, and a TCP port.
  • Trace a connection and read the resulting HTTP status.
  • Identify whether a failure happened during DNS, connection, or HTTP.

Builds on: Images and registries

Where a web request goes

You open a web browser and type http://127.0.0.1:8080/. What has to happen before you see a page? First, the operating system needs somewhere to send the packets. The address 127.0.0.1 is IPv4 loopback, an address for reaching the same machine from the current network view. A network interface is a connection point that can have addresses assigned to it. Loopback is one interface. Wi-Fi and virtual container interfaces are other examples.

A port is a number used by a transport protocol, such as TCP, to direct traffic to an application endpoint at an address. When nginx listens on TCP port 80 inside a container, a client needs a network path to that endpoint. In the example, Docker publishes a second endpoint on your machine’s loopback at port 8080, then forwards connections there to the container’s port 80.

After the connection opens, the client sends an HTTP request with a method and a path, such as GET /. The server sends back an HTTP response with a status, headers, and often a body. A 404 response is useful evidence. Something accepted the connection, understood HTTP, and said the requested path was missing.

Follow a request to a container port

The app listens on a container port. A published host port makes it reachable from the computer running Docker.

  1. Browser or curlConnect to localhost:8080
    HostThe client connects to the published port.
  2. Host port mappingForward to container port 80
    nginxThe running server receives the connection.
  3. nginxReturn HTTP response
    Browser or curlThe status and body are visible to the caller.
Follow the sequence

The app listens on a container port. A published host port makes it reachable from the computer running Docker.

Docker publishes only IPv4 loopback 8080 to container TCP 80; Kubernetes Services are introduced later.

Inspect the published port

Connect from the laptop to nginx and see which port belongs to each side of the connection.

1 / 4

From curlTo Published port

Publish a local host port

The Docker run command starts nginx and makes host TCP 8080 on loopback a published endpoint. The server inside the container listens on port 80.

Published endpoint
Before
No mapping
After
127.0.0.1:8080 → container port 80
Publish a local host port

The Docker run command starts nginx and makes host TCP 8080 on loopback a published endpoint. The server inside the container listens on port 80.

Uses a Docker port published to IPv4 loopback. The implementation of forwarding can differ across Docker hosts and Docker Desktop.

If curl returns an HTTP 404, did the connection reach an HTTP server?
Reveal prediction answer

Yes. The server received the request and answered that the path was missing.

Compare the two HTTP responses, then repeat the original request after stopping the container.

Run the loopback port exercise
Explore another case

Open Inspect the published port to trace the host connection to port 80 in the container. Compare a response from nginx with the connection failure after it stops. If port 8080 is already in use, replace the host port in the Docker and curl commands with 18081.

Connect to a container from your machine

Follow both numbers in the publish option from left to right. 8080 is where the browser connects on your machine. 80 is where nginx listens in its own network view. Binding the host side to loopback keeps this practice endpoint local. Execute the commands in order and compare the response headers for the two paths.

# Bind only the laptop's IPv4 loopback address for this local exercise.
# Host TCP 8080 forwards to the container's TCP 80.
docker run --rm -d --name network-demo \
  -p 127.0.0.1:8080:80 nginx:1.27.5
# Show HTTP response headers plus the response body.
curl -i http://127.0.0.1:8080/
# Ask for a path nginx does not serve.
curl -i http://127.0.0.1:8080/does-not-exist
# Release the published host port.
docker stop network-demo

Expect the first request to return a page. The second normally returns a 404 from nginx. After you stop the container, trying the first command again should fail to connect if no other program is listening there. Those outcomes tell you whether you reached the server, found the requested resource, or failed before sending HTTP.

What DNS does before the request

A URL with a hostname adds a step. The Domain Name System (DNS) lets the client look up records for a name. For a web connection, the client typically uses one of the returned IPv4 or IPv6 addresses. Several addresses can be valid. A successful lookup demonstrates name resolution. The client still has to connect to an address and receive an answer from the intended application.

Follow a hostname to its first response

A client resolves the hostname, connects to the returned address and the URL’s port, then sends its HTTP request.

  1. HTTP clientAsk for an address
    DNS resolverThe resolver returns an address for the hostname.
  2. HTTP clientConnect to the address and port
    Server listenerA successful connection opens a path to the process.
  3. HTTP clientSend GET /
    Web serverThe response shows that the app received the request.
Follow the sequence

A client resolves the hostname, connects to the returned address and the URL’s port, then sends its HTTP request.

A client obtains one IPv4 address; caching, IPv6 racing, and TLS details are simplified.

# This requires nslookup on your machine; any legitimate DNS answer may change.
nslookup kubernetes.io
# Verbose output separates connection setup from the HTTP response.
curl -v https://kubernetes.io/ -o /dev/null

Read the verbose curl output from the beginning. Look for a resolved address, the connection attempt, TLS negotiation for HTTPS, then the HTTP status. In later Kubernetes examples, the same sequence helps you trace requests to a Service from inside a Pod.

Find where a request failed

When a request breaks, form a prediction before changing anything. With a misspelled hostname, start at DNS. With the right address and the wrong port, look for a refused connection or timeout. With a real HTTP error, inspect the server, route, or application. Try the first version of this exercise with the module lab.

Check the address from the caller

The meaning of localhost follows where the client process runs. From a container it usually refers to that container’s network namespace. Connect from the same location as the failing client when testing a path.

Check your understanding

The request returns HTTP 404. Is changing the published port a useful first step?

Start with the response and the path. The request reached an HTTP server at the port you used. Check whether that server was the intended one and whether it has a route for that path.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu