Skip to content

Commit c79dfbf

Browse files
authored
Merge pull request #2359 from chenkaiyue/RetryGettingDockerRoot
Retry to get docker root and log when error
2 parents e8e2b2b + d553c74 commit c79dfbf

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

container/docker/factory.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strconv"
2323
"strings"
2424
"sync"
25+
"time"
2526

2627
"github.com/blang/semver"
2728
dockertypes "github.com/docker/docker/api/types"
@@ -49,6 +50,12 @@ var ArgDockerCA = flag.String("docker-tls-ca", "ca.pem", "path to trusted CA")
4950
// The namespace under which Docker aliases are unique.
5051
const DockerNamespace = "docker"
5152

53+
// The retry times for getting docker root dir
54+
const rootDirRetries = 5
55+
56+
//The retry period for getting docker root dir, Millisecond
57+
const rootDirRetryPeriod time.Duration = 1000 * time.Millisecond
58+
5259
// Regexp that identifies docker cgroups, containers started with
5360
// --cgroup-parent have another prefix than 'docker'
5461
var dockerCgroupRegexp = regexp.MustCompile(`([a-z0-9]{64})`)
@@ -72,10 +79,16 @@ var (
7279

7380
func RootDir() string {
7481
dockerRootDirOnce.Do(func() {
75-
status, err := Status()
76-
if err == nil && status.RootDir != "" {
77-
dockerRootDir = status.RootDir
78-
} else {
82+
for i := 0; i < rootDirRetries; i++ {
83+
status, err := Status()
84+
if err == nil && status.RootDir != "" {
85+
dockerRootDir = status.RootDir
86+
break
87+
} else {
88+
time.Sleep(rootDirRetryPeriod)
89+
}
90+
}
91+
if dockerRootDir == "" {
7992
dockerRootDir = *dockerRootDirFlag
8093
}
8194
})

0 commit comments

Comments
 (0)