Why host.docker.internal Died and `sed -i` Broke the Bind Mount
A Page That Answered Nothing
The report was one sentence: the file site does not open. Not an error page, not a certificate warning — a browser that spins and gives up.
The path for that hostname is long, and every hop is mine: Cloudflare, then a Cloudflare Tunnel, then nginx-limit-alist, then traefik-update-alist, then the application behind it. Five places for a request to die.
I wanted to know how far a request got, so I asked curl for the exchange and threw the body away:
curl -sv -o /dev/null https://drive.digikedai.com/
The TLS handshake completed, and the server returned HTTP 502 with a 0-byte body.
A completed handshake followed by a 502 with an empty body is a specific shape of failure. DNS is fine, the certificate is fine, the edge is reachable, and the request arrived somewhere inside my own network. Whatever is broken is behind the tunnel, not in front of it.
Layer One: A Name That Stopped Meaning What It Meant
The nginx config for that site proxied to host.docker.internal:5245. That name is convenient, and it is also a promise about how a container’s network namespace reaches the host — on this NAS it resolves to 172.17.0.1, the Docker bridge gateway. The bet is that the gateway can reach a port the host has published.
To test that bet directly, I ran a throwaway bridge container and asked it to touch the published port by every address the host could plausibly have. The config named port 5245; the port I could compare from both sides was 5244, so the table below measures 5244 — what it establishes is the container-to-host path, not one specific upstream port:
| Target from a bridge container | Port 5244 | Result |
|---|---|---|
172.17.0.1 (bridge gateway) | published | unreachable |
172.16.0.1 (second bridge) | published | unreachable |
192.168.1.1 (NAS LAN address) | published | unreachable |
| Same port from a LAN client | published | 200 |
Every container-side path dead, the LAN path healthy. That combination is not “Traefik is broken”: the LAN client still got 200 on the same port, so Traefik itself was still answering. The failure was container-to-host reachability. The Traefik stack had been recreated the night before, and this route was the one still pointing at the host gateway.
The fix is boring, and it removes the dependency rather than restoring it: address the upstream by container name on the shared Docker network.
# before
proxy_pass http://host.docker.internal:5245;
# after — resolved by Docker's DNS on the shared network
proxy_pass http://traefik-update-alist:5245;
host.docker.internal is a convenience that hides a dependency. A container name on the shared network is the same dependency stated out loud, and a name that does not resolve stops nginx at config-load time with host not found in upstream instead of at request time with a 502 and an empty body. What a container name does not fix is an address change: a static proxy_pass resolves and caches at reload time, so if traefik-update-alist is rebuilt and comes back on a different IP, the route goes quiet again until I reload nginx — or switch to a variable proxy_pass with a Docker resolver, which is the only way nginx re-resolves without a reload.
Layer Two: The Edit That Never Applied
With the upstream corrected, the site stayed down. This is the part worth the post.
The nginx config is a single file bind-mounted into the container. I edited it the way I edit everything:
sed -i 's#host.docker.internal:5245#traefik-update-alist:5245#' nginx.conf
docker exec nginx-limit-alist nginx -t # syntax is ok
docker exec nginx-limit-alist nginx -s reload
Config test passed. Reload succeeded. The site still returned 502, and the file inside the container still had the old upstream, because sed -i does not edit a file — it writes a new file and renames it over the old one. The single-file bind mount was created against the old inode, so it stays there while the path switches to a different inode. The container keeps reading the file that was unlinked, frozen at its last content.
The instrument that shows this is not cat on the host, and not nginx -t. It is the one that shows what the container can actually read:
docker exec nginx-limit-alist nginx -T | grep -n "proxy_pass .*5245"
# old upstream, from the loaded configuration
nginx -T starts a throwaway nginx that parses whatever the container’s mount namespace holds — not the file on the host disk. When those two disagree, the mount is stale. Once sed -i has already swapped the inode, the container has to be restarted so the mount reattaches to the file the path now points at — the corrected text is already on the host, and the restart is what makes the running process read it:
docker restart nginx-limit-alist
docker exec nginx-limit-alist nginx -T | grep -n "proxy_pass .*5245"
For the next edit, the point is to keep the inode. Write through the existing file instead of replacing it, and a reload is enough:
sed 's#host.docker.internal:5245#traefik-update-alist:5245#' nginx.conf > nginx.conf.next
cat nginx.conf.next > nginx.conf # truncate + write, same inode
rm nginx.conf.next
docker exec nginx-limit-alist nginx -s reload
What made this bug expensive was that both signals I trusted — nginx -t and the reload exit code — only validated syntax against the stale mount. Syntax was never the problem.
The Probe Alerts Now, Not a Person
The outage was found by a person, which is the actual defect. Nothing was watching either site from outside — not the file site, not the access portal.
I placed blackbox_exporter on the unRaid host rather than on DSM, separating the probe from the NAS serving the sites:
blackbox_exporterv0.27.0 as its own stack, 64 MiB memory limit, modulehttp_2xxforced to IPv4, following redirects, HTTPS required.- A Prometheus job (
blackbox-http) probing 13 public sites every 60 seconds, including drive.digikedai.com and access.hoelee.com. - A Grafana dashboard (
http-probes) for those probe results. - One alert rule:
probe_success == 0for 3 minutes → the existing Telegram + email channel, a message on down and one on recovery, 4-hour repeat.
I set a 3-minute window to avoid alerting on a single transient failure.
🔍 View the Prometheus scrape job and the alert rule (25 lines)
# prometheus.yml — job added beside the existing scrape targets
- job_name: blackbox-http
scrape_interval: 60s
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://drive.digikedai.com/
- https://access.hoelee.com/
# … 11 more public URLs
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: <blackbox-host>:9115
# alerts.yml
- alert: WebsiteDown
expr: probe_success == 0
for: 3m
labels: { severity: critical }
annotations:
summary: "{{ $labels.instance }} is not answering"
Recovered, and Checked From Outside
https://drive.digikedai.com/— 200, 125 ms, 19.9 KB;access.hoelee.comrecovered with the same change.- Upstream is now addressed by container name on the shared Docker network, so the route no longer depends on
host.docker.internal. If that container is rebuilt onto a new IP, it still needs a reload, or a variableproxy_passplus a Docker resolver. - The edit path is now write-through-the-same-inode, with verification inside the container (
nginx -T) instead of on the host file. - 13 public sites probed every 60 seconds from a second machine, one alert at three minutes of failure, delivered to the same channel as every other incident.
The lesson I keep re-learning on this infrastructure is that “it answered” and “it answered with something” are different assertions. A health check that accepts a completed TLS handshake as proof of life would have called both of these sites up.
Dealing with flaky containers, cloud cost bloat, or unexplained outages?
Real production reliability comes from understanding the kernel and the protocol layers, not just restarting containers. I manage 162 containers across 3 hosts running 24/7 client workloads.