From d048d21a526e516c77117f76f6da14e994e81331 Mon Sep 17 00:00:00 2001 From: siddharthist Date: Wed, 30 Dec 2015 13:16:18 -0600 Subject: [PATCH] Attempt sudo when docker commands fail --- dockerstatus/dockerstatus.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dockerstatus/dockerstatus.go b/dockerstatus/dockerstatus.go index be5a538..6939308 100644 --- a/dockerstatus/dockerstatus.go +++ b/dockerstatus/dockerstatus.go @@ -14,7 +14,12 @@ func DockerImageRepositories() (images []string, err error) { cmd := exec.Command("docker", "images") out, err := cmd.CombinedOutput() if err != nil { - return images, err + // try escalating to sudo, the error might have been one of permissions + cmd = exec.Command("sudo", "docker", "images") + out, err = cmd.CombinedOutput() + if err != nil { + return images, err + } } table := tabular.ProbabalisticSplit(string(out)) return tabular.GetColumnByHeader("REPOSITORIES", table), nil @@ -26,7 +31,11 @@ func RunningContainers() (containers []string, err error) { cmd := exec.Command("docker", "ps", "-a") out, err := cmd.CombinedOutput() if err != nil { - return containers, err + cmd = exec.Command("sudo", "docker", "ps", "-a") + out, err = cmd.CombinedOutput() + if err != nil { + return containers, err + } } // the output of `docker ps -a` has spaces in columns, but each column // is separated by 2 or more spaces. Just what Probabalistic was made for!