@@ -226,6 +226,25 @@ func ContainerAddrWithHost(name string, privatePort uint16, host string) string
226226 return host + ":" + strconv .Itoa (int (privatePort ))
227227}
228228
229+ func ContainerAddrWithHostRetry (name string , privatePort uint16 , host string ) string {
230+ maxAttempts := 30
231+ for attempt := range maxAttempts {
232+ c := getContainer (name )
233+ for _ , p := range c .Ports {
234+ if p .PrivatePort == privatePort {
235+ // Found the mapping - return immediately without waiting
236+ return host + ":" + strconv .Itoa (int (p .PublicPort ))
237+ }
238+ }
239+
240+ if attempt < maxAttempts - 1 {
241+ time .Sleep (500 * time .Millisecond )
242+ }
243+ }
244+
245+ return host + ":" + strconv .Itoa (int (privatePort ))
246+ }
247+
229248func ContainerAddrLocalhost (name string , privatePort uint16 ) string {
230249 return ContainerAddrWithHost (name , privatePort , "localhost" )
231250}
@@ -234,6 +253,10 @@ func ContainerAddr(name string, privatePort uint16) string {
234253 return ContainerAddrWithHost (name , privatePort , "0.0.0.0" )
235254}
236255
256+ func ContainerAddrRetry (name string , privatePort uint16 ) string {
257+ return ContainerAddrWithHostRetry (name , privatePort , "0.0.0.0" )
258+ }
259+
237260// DockerStart starts the specified services.
238261func DockerRun (instance string , op int ) error {
239262 c := getContainer (instance )
0 commit comments