Skip to content

Commit

Permalink
Merge pull request #121 from CiscoCloud/feature/docker-try-sudo
Browse files Browse the repository at this point in the history
Attempt sudo when docker commands fail
  • Loading branch information
langston-barrett committed Dec 30, 2015
2 parents 7944f69 + d048d21 commit ff3fbc5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions dockerstatus/dockerstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down

0 comments on commit ff3fbc5

Please sign in to comment.