From 6c7028426d821603e94e4412f2403a1d6b3716e5 Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 10 Apr 2024 15:58:11 -0400 Subject: [PATCH] Retry failed calls to MappedPort to workaround inspect problem --- docker.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docker.go b/docker.go index 6d10cf92a0..c4741ec6d8 100644 --- a/docker.go +++ b/docker.go @@ -158,6 +158,16 @@ func (c *DockerContainer) Host(ctx context.Context) (string, error) { // MappedPort gets externally mapped port for a container port func (c *DockerContainer) MappedPort(ctx context.Context, port nat.Port) (nat.Port, error) { + var mappedPort nat.Port + err := backoff.Retry(func() (err error) { + mappedPort, err = c.mappedPort(ctx, port) + return + }, backoff.WithContext(backoff.NewExponentialBackOff(), ctx)) + + return mappedPort, err +} + +func (c *DockerContainer) mappedPort(ctx context.Context, port nat.Port) (nat.Port, error) { inspect, err := c.inspectContainer(ctx) if err != nil { return "", err