Read a sample: 1. A Connection Has a Path
A developer starts a container, sees that the application is running, and sends a request to the host’s port. The request fails. A teammate tries the same application from inside the container and reports that it works.
Both observations can be true.
A connection does not travel directly from the word “container” to the word “application.” It has a starting point, a destination address, a transport protocol, and a destination port. Along the way, it may encounter a host interface, a published-port mapping, filtering rules, a container network, and finally a process that must be listening on an address reachable by that route.
Troubleshooting becomes easier when you stop asking only, “Is the port open?” and start asking, “Open to whom, at which address, using which protocol, and what evidence supports that conclusion?”
This chapter gives you a map for answering those questions. You do not need a working lab yet. The examples describe a small hypothetical service; Chapter 2 will help you build an environment in which you can perform tests safely.
Suppose an HTTP service is configured to use TCP port 8080. Someone says, “Port 8080 is open.” That statement leaves several important questions unanswered:
- Is a process listening on port 8080 inside the container?
- Is the service listening only on the container’s loopback address, or on an address other systems can reach?
- Has a host port been published to the container port?
- Is the test being made from the container, the host, another container, or a remote machine?
- Does “open” mean that a TCP connection succeeded, or that the application returned the expected response?
A useful observation includes the vantage point and the endpoint. For example:
> From the host, a TCP connection to 127.0.0.1 port 8080 succeeded, and the HTTP request returned a response.
That tells you more than “the port is open.” It identifies where the test originated and what was reached. It still does not prove that a different machine can connect, or that every application function is healthy.
An endpoint is commonly described by an IP address, a port, and a transport protocol. The address identifies where traffic is going; the port helps deliver that traffic to the intended service at that destination. TCP and UDP have separate port spaces, so TCP port 8080 and UDP port 8080 are not interchangeable.
For TCP, a successful connection shows that a connection was established to something at the tested endpoint. A refusal or timeout is evidence too, but neither identifies the cause on its own. UDP is different: it does not establish a connection in the same way, and a lack of response may be difficult to distinguish from filtering or an application that simply does not reply. Chapter 12 examines these results in more detail.
Imagine a client on another machine requesting an application through a Linux host. The host has an address of 192.0.2.10, and the application is intended to be available at TCP port 8080. The runtime is configured to publish that host port to TCP port 80 in a container.
Conceptually, the path is:
text
Remote client
|
| TCP to 192.0.2.10:8080
v
Host interface and applicable access rules
|
| Published host port 8080 to container port 80
v
Container networking
|
v
Application listening on a reachable container address, port 80
The two port numbers need not match. The client targets the host’s port 8080; the application listens on port 80 inside the container. If an operator checks only for a process listening on 8080 inside that container, they may conclude incorrectly that the application is missing.
This diagram is a model, not a promise about the implementation of every runtime. A runtime may use different forwarding mechanisms, and the order and location at which filtering is applied can vary with the platform and network configuration. Some containers use host networking or another arrangement in which a conventional published-port mapping is absent or has different significance.
The model is still useful because it separates questions that are often blurred together:
1. Can the client reach the intended host address?
2. Is the intended host address and port published for the correct protocol?
3. Can the runtime’s networking deliver traffic toward the container?
4. Is the application listening on the intended container port and an address reachable by that traffic?
5. Does the application respond correctly after the transport connection is made?
A failure at any one of these points can produce a failed request. A successful check at one point does not automatically validate the rest.
A process that accepts TCP connections normally creates a listening socket. The socket has a local address and port. Those details matter as much as the port number.
Consider two possible listening addresses inside a container:
text
127.0.0.1:80
0.0.0.0:80
The first is IPv4 loopback on port 80. It is intended for connections originating within that network namespace. A request from a process in the same container to 127.0.0.1:80 may succeed even if traffic arriving through the container’s network interface cannot reach that listener.
The second is the IPv4 wildcard address on port 80. It generally means the socket accepts traffic addressed to eligible IPv4 local addresses in that network namespace, subject to the rest of the network path and access controls. It does not mean that every remote client can reach the service, and it does not by…