From 838bf19db78045e86c74d8a9b5397d7644ba9e96 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 11 Nov 2026 22:40:28 +0200 Subject: [PATCH 1/3] fix(docker): stop update_container when the image pull fails before it starts A pull that fails before the stream begins (registry unreachable, DNS, TLS, auth) returns an HTTP error with a {"message":...} body. pullImage() now turns it into an error line, so update_container shows it, leaves the container alone and exits 1. --- .../include/DockerClient.php | 16 +++++++++++++++- .../scripts/update_container | 9 ++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php index 9ee25b6ab5..4152d1f3c4 100755 --- a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php +++ b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php @@ -923,7 +923,21 @@ public function pullImage($image, $callback=null) { ]))."\r\n"; } - $ret = $this->getDockerJSON("/images/create?fromImage=".urlencode($image), 'POST', $code, $callback, false, $header); + // The daemon streams {"error":...} only once the pull has started. Failures before that (registry + // unreachable, DNS, TLS, auth) come back as an HTTP error with a {"message":...} body, which the + // callers of this function do not look at. Turn such a reply into an "error" line for them. + $reported = false; + $wrapped = $callback ? function ($line) use ($callback, &$code, &$reported) { + $cnt = json_decode($line, true); + if (is_array($cnt) && isset($cnt['error'])) $reported = true; + elseif ($code !== true && is_array($cnt) && isset($cnt['message'])) { + $line = json_encode(['error' => $cnt['message']])."\n"; + $reported = true; + } + $callback($line); + } : null; + $ret = $this->getDockerJSON("/images/create?fromImage=".urlencode($image), 'POST', $code, $wrapped, false, $header); + if ($callback && $code !== true && !$reported) $callback(json_encode(['error' => is_string($code) ? $code : 'Pull failed'])."\n"); $this->flushCache($this::$imagesCache); return $ret; } diff --git a/emhttp/plugins/dynamix.docker.manager/scripts/update_container b/emhttp/plugins/dynamix.docker.manager/scripts/update_container index e753f3dcce..c5db0c64af 100755 --- a/emhttp/plugins/dynamix.docker.manager/scripts/update_container +++ b/emhttp/plugins/dynamix.docker.manager/scripts/update_container @@ -127,6 +127,8 @@ function pullImage_nchan($name, $image) { write("addLog\0
"._('TOTAL DATA PULLED').": ".$DockerClient->formatBytes(array_sum($alltotals))); if (!empty($strError)) { write("addLog\0
"._('Error').": ".htmlspecialchars($strError).""); + write("addLog\0"._('The container was not changed')); + my_logger("Pull of $image failed, container $name not updated"); return false; } return true; @@ -152,6 +154,7 @@ $style[] = "fieldset.docker{border:solid thin;margin-top:8px}"; $style[] = "legend{font-size:1.1rem!important;font-weight:bold}"; $style[] = ""; +$failed = false; write(implode($style)."

"); foreach (explode('*',rawurldecode($argv[1])) as $value) { $tmpl = $DockerTemplates->getUserTemplate($value); @@ -167,7 +170,10 @@ foreach (explode('*',rawurldecode($argv[1])) as $value) { $TS_Enabled = getXmlVal($xml, "TailscaleEnabled"); $oldImageID = $DockerClient->getImageID($Repository); // pull image - if (!pullImage_nchan($Name, $Repository)) continue; + if (!pullImage_nchan($Name, $Repository)) { + $failed = true; + continue; + } $oldContainerInfo = $DockerClient->getContainerDetails($Name); // determine if the container is still running $startContainer = false; @@ -207,4 +213,5 @@ foreach (explode('*',rawurldecode($argv[1])) as $value) { if ($oldImageID && $oldImageID != $newImageID) removeImage_nchan($oldImageID); } write('_DONE_',''); +exit($failed ? 1 : 0); ?> From 2b60471a5663377c0de90d8c6bf455c6d39ec6ae Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 16 Nov 2026 12:10:45 +0200 Subject: [PATCH 2/3] fix(docker): treat an empty pull error as unreported, end a failed update with _ERROR_ An HTTP error whose body is {"message":""} was marked as reported, so the status-based fallback was skipped and both pull helpers saw an empty error, which they treat as success. Count only non-empty error/message text. update_container now publishes _ERROR_ instead of _DONE_ when a pull failed, so a late _DONE_ record can no longer turn an Error modal back to Finished. --- .../plugins/dynamix.docker.manager/include/DockerClient.php | 5 +++-- .../plugins/dynamix.docker.manager/scripts/update_container | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php index 4152d1f3c4..35bf738e8a 100755 --- a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php +++ b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php @@ -926,11 +926,12 @@ public function pullImage($image, $callback=null) { // The daemon streams {"error":...} only once the pull has started. Failures before that (registry // unreachable, DNS, TLS, auth) come back as an HTTP error with a {"message":...} body, which the // callers of this function do not look at. Turn such a reply into an "error" line for them. + // An empty message does not count as reported: the callers treat an empty error as success. $reported = false; $wrapped = $callback ? function ($line) use ($callback, &$code, &$reported) { $cnt = json_decode($line, true); - if (is_array($cnt) && isset($cnt['error'])) $reported = true; - elseif ($code !== true && is_array($cnt) && isset($cnt['message'])) { + if (is_array($cnt) && isset($cnt['error']) && $cnt['error'] !== '') $reported = true; + elseif ($code !== true && is_array($cnt) && isset($cnt['message']) && $cnt['message'] !== '') { $line = json_encode(['error' => $cnt['message']])."\n"; $reported = true; } diff --git a/emhttp/plugins/dynamix.docker.manager/scripts/update_container b/emhttp/plugins/dynamix.docker.manager/scripts/update_container index c5db0c64af..d485146c8c 100755 --- a/emhttp/plugins/dynamix.docker.manager/scripts/update_container +++ b/emhttp/plugins/dynamix.docker.manager/scripts/update_container @@ -212,6 +212,6 @@ foreach (explode('*',rawurldecode($argv[1])) as $value) { // remove old orphan image since it's no longer used by this container if ($oldImageID && $oldImageID != $newImageID) removeImage_nchan($oldImageID); } -write('_DONE_',''); +write($failed ? '_ERROR_' : '_DONE_',''); exit($failed ? 1 : 0); ?> From 042d21fbe3318c0724511b3b06b36b4891c24843 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 16 Nov 2026 12:14:11 +0200 Subject: [PATCH 3/3] fix(docker): use empty() for the pull error check, matching the callers The pull helpers test the error with !empty(), so a "0" message is also treated as success there. Count an error/message as reported only when it is !empty() too, so such a reply also gets the status-based fallback. --- .../plugins/dynamix.docker.manager/include/DockerClient.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php index 35bf738e8a..af487dba94 100755 --- a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php +++ b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php @@ -926,12 +926,12 @@ public function pullImage($image, $callback=null) { // The daemon streams {"error":...} only once the pull has started. Failures before that (registry // unreachable, DNS, TLS, auth) come back as an HTTP error with a {"message":...} body, which the // callers of this function do not look at. Turn such a reply into an "error" line for them. - // An empty message does not count as reported: the callers treat an empty error as success. + // An empty message ("", "0") does not count as reported: the callers treat an empty() error as success. $reported = false; $wrapped = $callback ? function ($line) use ($callback, &$code, &$reported) { $cnt = json_decode($line, true); - if (is_array($cnt) && isset($cnt['error']) && $cnt['error'] !== '') $reported = true; - elseif ($code !== true && is_array($cnt) && isset($cnt['message']) && $cnt['message'] !== '') { + if (is_array($cnt) && !empty($cnt['error'])) $reported = true; + elseif ($code !== true && is_array($cnt) && !empty($cnt['message'])) { $line = json_encode(['error' => $cnt['message']])."\n"; $reported = true; }