Hi there,
I’m working with Docker to build a Flutter app through act-cli
, but I’m encountering an issue where Gradle cannot connect to 127.0.0.1
during the build process. Initially, this seemed like a network issue with Docker’s default network configuration.
But then I checked the Gradle log and figured out some endpoint link to the port 127.0.0.1
2024-12-14T05:04:39.937+0000 [DEBUG] [org.gradle.launcher.daemon.bootstrap.DaemonMain] Assuming the daemon was started with following jvm opts: [--add-opens=java.base/java.util=ALL-UNNAMED, --add-opens=java.base/java.lang=ALL-UNNAMED, --add-opens=java.base/java.lang.invoke=ALL-UNNAMED, --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED, --add-opens=java.base/java.nio.charset=ALL-UNNAMED, --add-opens=java.base/java.net=ALL-UNNAMED, --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED, -Xmx1000m, -Dfile.encoding=UTF-8, -Duser.country=US, -Duser.language=en, -Duser.variant]
2024-12-14T05:04:40.004+0000 [INFO] [org.gradle.launcher.daemon.server.Daemon] start() called on daemon - DefaultDaemonContext[uid=476a22cb-6485-4d7c-a6b1-b142c4c80e15,javaHome=/usr/lib/jvm/java-17-openjdk-amd64,javaVersion=17,javaVendor=Ubuntu,daemonRegistryDir=/root/.gradle/daemon,pid=533,idleTimeout=120000,priority=NORMAL,applyInstrumentationAgent=true,nativeServicesMode=ENABLED,daemonOpts=--add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1000m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
2024-12-14T05:04:40.018+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface docker0
2024-12-14T05:04:40.018+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2024-12-14T05:04:40.018+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /172.17.0.1
2024-12-14T05:04:40.019+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface br-1ac2cbf1abc1
2024-12-14T05:04:40.019+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2024-12-14T05:04:40.019+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /172.18.0.1
2024-12-14T05:04:40.019+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface eth0
2024-12-14T05:04:40.019+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /fdc4:f303:9324:0:0:0:0:3%eth0
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /fe80:0:0:0:c91:dfff:fef2:8afa%eth0
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /192.168.65.3
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface services1
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /fe80:0:0:0:309a:5ff:fe7f:5efe%services1
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /fdc4:f303:9324:0:0:0:0:6%services1
2024-12-14T05:04:40.020+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /192.168.65.6
2024-12-14T05:04:40.021+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface lo
2024-12-14T05:04:40.021+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? true
2024-12-14T05:04:40.021+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding loopback address /0:0:0:0:0:0:0:1%lo
2024-12-14T05:04:40.021+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding loopback address /127.0.0.1
2024-12-14T05:04:40.022+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.TcpIncomingConnector] Listening on [f0396ef3-6600-4fa1-9305-cebee6fdd858 port:35595, addresses:[localhost/127.0.0.1]].
2024-12-14T05:04:40.028+0000 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] Daemon starting at: Sat Dec 14 05:04:40 GMT 2024, with address: [f0396ef3-6600-4fa1-9305-cebee6fdd858 port:35595, addresses:[localhost/127.0.0.1]]
2024-12-14T05:04:40.029+0000 [INFO] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Advertising the daemon address to the clients: [f0396ef3-6600-4fa1-9305-cebee6fdd858 port:35595, addresses:[localhost/127.0.0.1]]
2024-12-14T05:04:40.029+0000 [DEBUG] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Advertised daemon context: DefaultDaemonContext[uid=476a22cb-6485-4d7c-a6b1-b142c4c80e15,javaHome=/usr/lib/jvm/java-17-openjdk-amd64,javaVersion=17,javaVendor=Ubuntu,daemonRegistryDir=/root/.gradle/daemon,pid=533,idleTimeout=120000,priority=NORMAL,applyInstrumentationAgent=true,nativeServicesMode=ENABLED,daemonOpts=--add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1000m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
2024-12-14T05:04:40.030+0000 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Storing daemon address: [f0396ef3-6600-4fa1-9305-cebee6fdd858 port:35595, addresses:[localhost/127.0.0.1]], context: DefaultDaemonContext[uid=476a22cb-6485-4d7c-a6b1-b142c4c80e15,javaHome=/usr/lib/jvm/java-17-openjdk-amd64,javaVersion=17,javaVendor=Ubuntu,daemonRegistryDir=/root/.gradle/daemon,pid=533,idleTimeout=120000,priority=NORMAL,applyInstrumentationAgent=true,nativeServicesMode=ENABLED,daemonOpts=--add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1000m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
...
(more)
The critical error is that the Gradle daemon couldn’t been connected
What went wrong:
Could not connect to the Gradle daemon.
Daemon uid: 908223a2-5fc1-4129-9952-a4c2edad0ed7 with diagnostics:
Daemon pid: 14720
After a very long trial and errors, with various combination on config I solved the problem by turn-off the network host on Docker Desktop ( I am using Window 10 and Docker Desktop).
Then my intuition suggest me to check the host
file (in C:\Windows\System32\drivers\etc
)
Looked like I intentionally put two record to block distracting site using 127.0.0.1
127.0.0.1 9gag.com
127.0.0.1 facebook.com
By removing the two lines, the problem had been solved. But I want to study & understand why it happened from the first place.
In summary, here’s the sequence of what happened:
- I couldn’t run
flutter build
because Gradle couldn’t connect to127.0.0.1
. - The problem was resolved when I disabled Docker’s host network mode (
--network host
). - I then found that the issue was fixed (even on network host) when I removed two blocked entries in my hosts file that were redirecting certain domains to
127.0.0.1
.
I want to deeply understand how these blocked lines in the hosts file (redirecting domain names to 127.0.0.1
) are interfering with Docker’s networking and communication. Specifically: How does routing 127.0.0.1
for certain domains affect Docker containers and their ability to access services running on the host (like Gradle)?
Any insights on the relationship between Docker’s network stack and the host file would be really helpful!
Edit 12/15/2024
It’s more likely that I was wrong. I tested again with the two line removed and then readded later then it turns out the error STILL HAPPENED. So that mean the only way to fix it is to TURN-OFF the NETWORK HOST. So sorry for the confusion I caused!