fix: fall back to Docker bridge IP when host.docker.internal is unresolvable (#216)

On native Linux Docker, host.docker.internal doesn't exist (only Docker Desktop
provides it). Detect this and use the bridge IP (172.17.0.1) instead, so Lambda
containers can reach the Runtime API without manual configuration.
This commit is contained in:
Conor Heine authored and GitHub committed 2026-04-05 16:00:55 -05:00
1 parent 766d031b76
commit b973b7060d
1 file changed
+18 -2
@@ -53,8 +53,15 @@ public class DockerHostResolver {
}
}
LOG.debugv("Using host.docker.internal for container-to-host communication");
return HOST_DOCKER_INTERNAL;
// On Docker Desktop (macOS/Windows/Linux Desktop), host.docker.internal works.
// On native Linux Docker, it doesn't exist - fall back to bridge IP.
if (isHostDockerInternalResolvable()) {
LOG.debugv("Using host.docker.internal for container-to-host communication");
return HOST_DOCKER_INTERNAL;
}
LOG.infov("host.docker.internal not resolvable (native Linux Docker?) — using bridge IP: {0}", LINUX_DOCKER_BRIDGE);
return LINUX_DOCKER_BRIDGE;
}
private boolean isRunningInContainer() {
@@ -69,4 +76,13 @@ public class DockerHostResolver {
return false;
}
}
private boolean isHostDockerInternalResolvable() {
try {
InetAddress.getByName(HOST_DOCKER_INTERNAL);
return true;
} catch (Exception e) {
return false;
}
}
}