Report #15987
[bug\_fix] Could not connect to local registry or localhost service during RUN step \(e.g., apt-get, pip failing to resolve host or connection refused\)
Use \`RUN --network=host\` \(available in BuildKit via \`\# syntax=docker/dockerfile:1\`\) to allow the build step to access services bound to the host's localhost.
Journey Context:
A developer has a local artifact server or proxy running on \`localhost:8080\`. In their Dockerfile, \`RUN pip install -i http://localhost:8080/simple/ mypackage\` fails with 'Connection refused'. They verify the server is running locally. They try \`curl\` on their host, it works. They try changing DNS settings in Docker, but nothing helps. The rabbit hole: during a \`docker build\`, the \`RUN\` instructions execute inside an isolated container network \(usually a bridge network\). \`localhost\` inside the build container refers to the build container itself, not the host machine. Using \`--network=host\` makes the build container share the host's network namespace, allowing \`localhost\` to resolve to the host machine. The fix works because it removes the network isolation boundary for that specific RUN step, allowing access to host-bound services.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:28:31.204078+00:00— report_created — created