From 6fd88575b278bda45578a22d5717e890c4ec45e0 Mon Sep 17 00:00:00 2001 From: Derek Kaser <11674153+dkaser@users.noreply.github.com> Date: Tue, 1 Oct 2024 04:21:51 +0000 Subject: [PATCH] fix: prevent deleting containers that are assigned as a network --- .../dynamix.docker.manager/include/DockerClient.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php index b985c1be5..dc60818a2 100644 --- a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php +++ b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php @@ -824,6 +824,13 @@ class DockerClient { global $docroot, $dockerManPaths; $id = $id ?: $name; $info = DockerUtil::loadJSON($dockerManPaths['webui-info']); + + // Check to see if the container is linked to other containers + $networks = array_map(function ($n) { return $n['NetworkMode']; }, $this->getDockerContainers()); + if (in_array("container:{$name}", $networks)) { + return "Container currently assigned as network for another container."; + } + // Attempt to remove container $this->getDockerJSON("/containers/$id?force=1", 'DELETE', $code); if (isset($info[$name])) {