@@ -22,6 +22,7 @@ import (
22
22
"strconv"
23
23
"strings"
24
24
"sync"
25
+ "time"
25
26
26
27
"github.com/blang/semver"
27
28
dockertypes "github.com/docker/docker/api/types"
@@ -49,6 +50,12 @@ var ArgDockerCA = flag.String("docker-tls-ca", "ca.pem", "path to trusted CA")
49
50
// The namespace under which Docker aliases are unique.
50
51
const DockerNamespace = "docker"
51
52
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
+
52
59
// Regexp that identifies docker cgroups, containers started with
53
60
// --cgroup-parent have another prefix than 'docker'
54
61
var dockerCgroupRegexp = regexp .MustCompile (`([a-z0-9]{64})` )
@@ -72,10 +79,16 @@ var (
72
79
73
80
func RootDir () string {
74
81
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 == "" {
79
92
dockerRootDir = * dockerRootDirFlag
80
93
}
81
94
})
0 commit comments