Fix docker updates occasionally trying to remove wrong image

https://forums.lime-technology.com/topic/57985-docker-failure-to-remove-orphan-image-due-to-similar-named-image/

Also handles rare edge case of multiple containers installed with different tags all referring to an identical image at the time of upgrade
This commit is contained in:
Squidly271
2017-12-15 18:39:37 -05:00
parent ed815a3015
commit 28e610735a
@@ -896,15 +896,19 @@ class DockerClient {
public function getImageID($Image) {
if ( ! strpos($Image,":") ) {
$Image .= ":latest";
}
foreach ($this->getDockerImages() as $img) {
if (preg_match("%" . preg_quote($Image, "%") . "%", $img["Tags"][0])) {
return $img["Id"];
foreach ($img['Tags'] as $tag) {
if ( $Image == $tag ) {
return $img["Id"];
}
}
}
return null;
}
public function getImageName($id) {
foreach ($this->getDockerImages() as $img) {
if ($img['Id'] == $id) {
@@ -914,7 +918,6 @@ class DockerClient {
return null;
}
private function usedBy($imageId) {
$out = [];
foreach ($this->getDockerContainers() as $ct) {