@@ -8,17 +8,18 @@ import (
8
8
"github.com/dapr/cli/utils"
9
9
)
10
10
11
- // Uninstall deletes all installed containers
12
- func Uninstall (uninstallAll bool , dockerNetwork string ) error {
13
- var errs []error
11
+ func removeContainers (uninstallAll bool , dockerNetwork string ) []error {
12
+ var containerErrs []error
14
13
15
14
_ , err := utils .RunCmdAndWait (
16
15
"docker" , "rm" ,
17
16
"--force" ,
18
17
utils .CreateContainerName (DaprPlacementContainerName , dockerNetwork ))
19
18
20
19
if err != nil {
21
- errs = append (errs , fmt .Errorf ("could not remove %s container: %s" , DaprPlacementContainerName , err ))
20
+ containerErrs = append (
21
+ containerErrs ,
22
+ fmt .Errorf ("could not remove %s container: %s" , DaprPlacementContainerName , err ))
22
23
}
23
24
24
25
_ , err = utils .RunCmdAndWait (
@@ -27,7 +28,9 @@ func Uninstall(uninstallAll bool, dockerNetwork string) error {
27
28
daprDockerImageName )
28
29
29
30
if err != nil {
30
- errs = append (errs , fmt .Errorf ("could not remove %s container: %s" , daprDockerImageName , err ))
31
+ containerErrs = append (
32
+ containerErrs ,
33
+ fmt .Errorf ("could not remove %s image: %s" , daprDockerImageName , err ))
31
34
}
32
35
33
36
if uninstallAll {
@@ -36,21 +39,39 @@ func Uninstall(uninstallAll bool, dockerNetwork string) error {
36
39
"--force" ,
37
40
utils .CreateContainerName (DaprRedisContainerName , dockerNetwork ))
38
41
if err != nil {
39
- errs = append (errs , fmt .Errorf ("could not remove %s container: %s" , DaprRedisContainerName , err ))
42
+ containerErrs = append (
43
+ containerErrs ,
44
+ fmt .Errorf ("could not remove %s container: %s" , DaprRedisContainerName , err ))
40
45
}
41
46
}
42
47
43
- err = rundata .DeleteRunDataFile ()
48
+ return containerErrs
49
+ }
50
+
51
+ // Uninstall deletes all installed containers
52
+ func Uninstall (uninstallAll bool , dockerNetwork string ) error {
53
+ var containerErrs []error
54
+
55
+ dockerInstalled := utils .IsDockerInstalled ()
56
+ if dockerInstalled {
57
+ containerErrs = removeContainers (uninstallAll , dockerNetwork )
58
+ }
59
+
60
+ err := rundata .DeleteRunDataFile ()
44
61
if err != nil {
45
62
fmt .Println ("WARNING: could not delete run data file" )
46
63
}
47
64
48
- if len (errs ) == 0 {
65
+ err = errors .New ("uninstall failed" )
66
+ if ! dockerInstalled {
67
+ return fmt .Errorf ("%w \n could not connect to Docker. Docker may not be installed or running" , err )
68
+ }
69
+
70
+ if len (containerErrs ) == 0 {
49
71
return nil
50
72
}
51
73
52
- err = errors .New ("uninstall failed" )
53
- for _ , e := range errs {
74
+ for _ , e := range containerErrs {
54
75
err = fmt .Errorf ("%w \n %s" , err , e )
55
76
}
56
77
return err
0 commit comments