@@ -51,28 +51,51 @@ func getProtocols() []p2pProtocol {
5151// is the host's address visible from bridge containers.
5252//
5353// Detection order:
54- // 1. docker0 interface IPv4 address (Docker bridge gateway)
55- // 2. Fallback to 127.0.0.1 (works when kubo is also on host network)
54+ // 1. docker0 interface IPv4 address (Docker default bridge gateway)
55+ // 2. Any Docker Compose bridge (br-<hash>) IPv4 address
56+ // 3. Fallback to 127.0.0.1 (works when kubo is also on host network)
5657func resolveProxyTargetIP () string {
57- iface , err := net .InterfaceByName ("docker0" )
58+ // 1. Try docker0 (default Docker bridge)
59+ if ip := getIPv4FromInterface ("docker0" ); ip != "" {
60+ log .Infow ("Detected Docker bridge IP for proxy target" , "iface" , "docker0" , "ip" , ip )
61+ return ip
62+ }
63+
64+ // 2. Try any Docker Compose bridge (br-<hash>)
65+ ifaces , err := net .Interfaces ()
66+ if err == nil {
67+ for _ , iface := range ifaces {
68+ if strings .HasPrefix (iface .Name , "br-" ) {
69+ if ip := getIPv4FromInterface (iface .Name ); ip != "" {
70+ log .Infow ("Detected Docker Compose bridge IP for proxy target" , "iface" , iface .Name , "ip" , ip )
71+ return ip
72+ }
73+ }
74+ }
75+ }
76+
77+ // 3. Fallback
78+ log .Debug ("No Docker bridge interface found, using 127.0.0.1 for proxy target" )
79+ return "127.0.0.1"
80+ }
81+
82+ // getIPv4FromInterface returns the first IPv4 address of the named interface,
83+ // or "" if the interface doesn't exist or has no IPv4 address.
84+ func getIPv4FromInterface (name string ) string {
85+ iface , err := net .InterfaceByName (name )
5886 if err != nil {
59- log .Debugw ("No docker0 interface found, using 127.0.0.1 for proxy target" , "err" , err )
60- return "127.0.0.1"
87+ return ""
6188 }
6289 addrs , err := iface .Addrs ()
6390 if err != nil {
64- log .Warnw ("Failed to get docker0 addresses, using 127.0.0.1" , "err" , err )
65- return "127.0.0.1"
91+ return ""
6692 }
6793 for _ , addr := range addrs {
6894 if ipnet , ok := addr .(* net.IPNet ); ok && ipnet .IP .To4 () != nil {
69- ip := ipnet .IP .String ()
70- log .Infow ("Detected Docker bridge IP for proxy target" , "ip" , ip )
71- return ip
95+ return ipnet .IP .String ()
7296 }
7397 }
74- log .Debug ("No IPv4 on docker0, using 127.0.0.1 for proxy target" )
75- return "127.0.0.1"
98+ return ""
7699}
77100
78101// registerKuboProtocols registers p2p protocol listeners on kubo via its HTTP API.
0 commit comments