From a59cc208eebfdbd90c13e137041620aa01f0d6ea Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 17 Apr 2022 22:56:48 +0200 Subject: [PATCH] Docker: add route for remote WireGuard access Containers with network 'br0' can be remotely accessed by WireGuard without the need to configure static router on the home router (gateway) "Host access to custom networks" must be enabled to allow access --- .../include/CreateDocker.php | 10 +++++++--- .../include/DockerClient.php | 8 +++++--- .../include/Helpers.php | 19 ++++++++++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/plugins/dynamix.docker.manager/include/CreateDocker.php b/plugins/dynamix.docker.manager/include/CreateDocker.php index 488f8491b..bda3d324f 100644 --- a/plugins/dynamix.docker.manager/include/CreateDocker.php +++ b/plugins/dynamix.docker.manager/include/CreateDocker.php @@ -1,7 +1,7 @@
'; goto END; @@ -175,15 +176,18 @@ if (isset($_GET['updateContainer'])){ if ($echo && !pullImage($Name, $Repository)) continue; $oldContainerInfo = $DockerClient->getContainerDetails($Name); // determine if the container is still running + $startContainer = false; if (!empty($oldContainerInfo) && !empty($oldContainerInfo['State']) && !empty($oldContainerInfo['State']['Running'])) { // since container was already running, put it back it to a running state after update $cmd = str_replace('/docker create ', '/docker run -d ', $cmd); + $startContainer = true; // attempt graceful stop of container first stopContainer($Name, $echo); } // force kill container if still running after 10 seconds if (empty($_GET['communityApplications'])) removeContainer($Name, $echo); execCommand($cmd, $echo); + if ($startContainer) addRoute($Name); // add route for remote WireGuard access $DockerClient->flushCaches(); $newImageID = $DockerClient->getImageID($Repository); // remove old orphan image since it's no longer used by this container diff --git a/plugins/dynamix.docker.manager/include/DockerClient.php b/plugins/dynamix.docker.manager/include/DockerClient.php index 36d2aee6a..8d4555a0e 100644 --- a/plugins/dynamix.docker.manager/include/DockerClient.php +++ b/plugins/dynamix.docker.manager/include/DockerClient.php @@ -1,7 +1,7 @@ getDockerJSON("/containers/$id/start", 'POST', $code); $this->flushCache($this::$containersCache); + addRoute($id); // add route for remote WireGuard access return $code; } @@ -788,6 +789,7 @@ class DockerClient { public function restartContainer($id) { $this->getDockerJSON("/containers/$id/restart", 'POST', $code); $this->flushCache($this::$containersCache); + addRoute($id); // add route for remote WireGuard access return $code; } diff --git a/plugins/dynamix.docker.manager/include/Helpers.php b/plugins/dynamix.docker.manager/include/Helpers.php index 0a6cece63..df3c14523 100644 --- a/plugins/dynamix.docker.manager/include/Helpers.php +++ b/plugins/dynamix.docker.manager/include/Helpers.php @@ -1,7 +1,7 @@ /dev/null"); + } +} + function xml_encode($string) { return htmlspecialchars($string, ENT_XML1, 'UTF-8'); }