Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

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

Conor Heineb973b7060d4c
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/DockerHostResolver.java b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/DockerHostResolver.java
index 940eb5154d..338d0c67ed 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/DockerHostResolver.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/DockerHostResolver.java
@@ -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;
+ }
+ }
}