fix: refactor retrieval of network and docker inspect information
This commit is contained in:
committed by
Michael Hobbs
parent
25759bcbb4
commit
31333452c8
@@ -158,7 +158,7 @@ func VerifyImage(image string) bool {
|
||||
|
||||
// ContainerIsRunning checks to see if a container is running
|
||||
func ContainerIsRunning(containerId string) bool {
|
||||
b, err := sh.Command("docker", "inspect", "--format", "'{{.State.Running}}'", containerId).Output()
|
||||
b, err := DockerInspect(containerId, "'{{.State.Running}}'")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -175,6 +175,20 @@ func DirectoryExists(filePath string) bool {
|
||||
return fi.IsDir()
|
||||
}
|
||||
|
||||
// DockerInspect runs an inspect command with a given format against a container id
|
||||
func DockerInspect(containerId, format string) (string, error) {
|
||||
b, err := sh.Command("docker", "inspect", "--format", format, containerId).Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
output := strings.TrimSpace(string(b[:]))
|
||||
if strings.HasPrefix(output, "'") && strings.HasSuffix(output, "'") {
|
||||
output = strings.TrimSuffix(strings.TrimPrefix(output, "'"), "'")
|
||||
}
|
||||
return output, err
|
||||
|
||||
}
|
||||
|
||||
// DokkuApps returns a list of all local apps
|
||||
func DokkuApps() ([]string, error) {
|
||||
var apps []string
|
||||
|
||||
Reference in New Issue
Block a user