Skip to content

Commit

Permalink
Retry failed calls to MappedPort to workaround inspect problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tylfin committed Apr 18, 2024
1 parent a3ff7aa commit 6c70284
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c70284

Please sign in to comment.