basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Socket bind address: 127.0.0.1 for host-only, 0.0.0.0 for all interfaces

    A service bound to 127.0.0.1:8080 accepts connections only from the same host and always returns Connection refused from outside, even with the firewall open. A service on 0.0.0.0:8080 is reachable on every interface — including the public one.

    What the address in Local Address:Port means

    In Linux, a socket binds to an address + port pair, rather than a standalone port number (Ports and sockets):

    Address in ss -tulnp Where the kernel accepts connections from Best suited for
    127.0.0.1:8080 ([::1]:8080) The host itself only (the lo interface) Local databases, metrics, admin panels behind a reverse proxy or SSH tunnel
    10.0.0.11:8080 Only the interface carrying that IP (e.g., LAN or WireGuard wg0) Internal service kept off the public address
    0.0.0.0:8080 (*:8080) Every IPv4 interface on the host Public service (sshd, proxy) or a process inside a container
    [::]:8080 Every IPv6 and IPv4 interface (when net.ipv6.bindv6only = 0) Same as 0.0.0.0, with dual-stack support

    The Docker container trap

    Inside a container, lo belongs to the container’s own netns (Linux network stack). If an app inside a container binds to 127.0.0.1:8080, neither the host’s docker-proxy nor Traefik on a shared Docker network can reach it — external callers get Empty reply from server or Connection reset by peer.

    Inside a container, bind the service to 0.0.0.0:8080, then restrict external access on the host side — either by publishing on loopback in Compose (ports: - "127.0.0.1:8080:8080", A host-only port goes on 127.0.0.1) or by omitting ports: altogether when traffic enters through a reverse proxy network.

    How to check

    Inspect the Local Address:Port column in sudo ss -tulnp:

    sudo ss -tulnp
    # Netid State  Recv-Q Send-Q Local Address:Port Peer Address:Port Process
    # tcp   LISTEN 0      4096         0.0.0.0:22        0.0.0.0:*    users:(("sshd",pid=1142,fd=3))
    # tcp   LISTEN 0      4096       127.0.0.1:8080      0.0.0.0:*    users:(("docker-proxy",pid=1821,fd=7))
    # tcp   LISTEN 0      4096       10.0.0.11:8088      0.0.0.0:*    users:(("docker-proxy",pid=1708,fd=7))

    Port 22 is open on all interfaces, 8080 is reachable only locally on the server, and 8088 is exposed only on the interface holding 10.0.0.11.

    Also in this chapter