@@ -27,6 +27,7 @@ import (
2727 "time"
2828
2929 "github.com/docker/docker/client"
30+ "github.com/docker/go-connections/nat"
3031
3132 "github.com/docker/docker/api/types"
3233 "github.com/docker/docker/api/types/container"
@@ -208,8 +209,20 @@ func deployImage(
208209 },
209210 }, & container.HostConfig {
210211 PublishAllPorts : true ,
211- ExtraHosts : extraHosts ,
212- Mounts : mounts ,
212+ PortBindings : nat.PortMap {
213+ nat .Port ("8008/tcp" ): []nat.PortBinding {
214+ {
215+ HostIP : "127.0.0.1" ,
216+ },
217+ },
218+ nat .Port ("8448/tcp" ): []nat.PortBinding {
219+ {
220+ HostIP : "127.0.0.1" ,
221+ },
222+ },
223+ },
224+ ExtraHosts : extraHosts ,
225+ Mounts : mounts ,
213226 }, & network.NetworkingConfig {
214227 EndpointsConfig : map [string ]* network.EndpointSettings {
215228 contextStr : {
@@ -263,12 +276,24 @@ func deployImage(
263276 if cfg .DebugLoggingEnabled {
264277 log .Printf ("%s: Started container %s" , contextStr , containerID )
265278 }
279+
280+ // We need to hammer the inspect endpoint until the ports show up, they don't appear immediately.
266281 var inspect types.ContainerJSON
267- inspect , err = docker .ContainerInspect (ctx , containerID )
282+ var baseURL , fedBaseURL string
283+ inspectStartTime := time .Now ()
284+ for time .Since (inspectStartTime ) < time .Second {
285+ inspect , err = docker .ContainerInspect (ctx , containerID )
286+ if err != nil {
287+ return nil , err
288+ }
289+ baseURL , fedBaseURL , err = endpoints (inspect .NetworkSettings .Ports , 8008 , 8448 )
290+ if err == nil {
291+ break
292+ }
293+ }
268294 if err != nil {
269- return nil , err
295+ return nil , fmt . Errorf ( "%s : image %s : %w" , contextStr , imageID , err )
270296 }
271-
272297 for vol := range inspect .Config .Volumes {
273298 log .Printf (
274299 "WARNING: %s has a named VOLUME %s - volumes can lead to unpredictable behaviour due to " +
@@ -280,10 +305,6 @@ func deployImage(
280305 }
281306 log .Printf ("%s port bindings: %+v" , containerName , inspect .NetworkSettings .Ports )
282307
283- baseURL , fedBaseURL , err := endpoints (inspect .NetworkSettings .Ports , 8008 , 8448 )
284- if err != nil {
285- return nil , fmt .Errorf ("%s : image %s : %w" , contextStr , imageID , err )
286- }
287308 var lastErr error
288309
289310 // Inspect health status of container to check it is up
0 commit comments