Created
June 17, 2019 17:21
-
-
Save nerdalert/b9cefaac4582c88eb71eeaab758e5e1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Check that the image name in the Docker Container matches the image name being inspected | |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
func checkDockerImageName(dockerImage string, containerID string) bool { | |
if containerID == "" { | |
errMessage := "The container id/name is blank!" | |
printError(errMessage) | |
inspectionData.ProcessesResults = append(inspectionData.ProcessesResults, formatHTMLError(errMessage)) | |
return false | |
} | |
var dockerCommand string | |
// Determine correct docker command syntax as the syntax changed after 1.12 | |
if strings.Contains(inspectionData.SystemDockerClientVersion, "1.12") { | |
dockerCommand = "docker inspect --format '{{.Config.Image}}' " + containerID | |
} else { | |
dockerCommand = "docker container inspect --format '{{.Config.Image}}' " + containerID | |
} | |
output, err := runCommand(dockerCommand) | |
if err != nil { | |
errMessage := "Unable to retrieve the image name from the Docker container!" | |
if output != "" { | |
errMessage = errMessage + ", " + output | |
} else { | |
errMessage = errMessage + ", " + err.Error() | |
} | |
printError(errMessage) | |
inspectionData.ProcessesResults = append(inspectionData.ProcessesResults, formatHTMLError(errMessage)) | |
return false | |
} | |
if output != dockerImage { | |
errMessage := "The container " + containerID + " is running from the docker image " + output + ", and not from the docker image " + dockerImage + " being inspected!" | |
printError(errMessage) | |
inspectionData.ProcessesResults = append(inspectionData.ProcessesResults, formatHTMLError(errMessage)) | |
return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment