From 4dc7175588c30ad052b48feaac69206da81b02c5 Mon Sep 17 00:00:00 2001 From: Tim Dreyer <74516735+eyerrock@users.noreply.github.com> Date: Thu, 24 Apr 2025 22:32:58 +0200 Subject: [PATCH 1/6] refactor: docker container list --- docker/Dockerfile | 2 + docker/README.md | 8 + docker/docker-compose.yml | 2 + src/web/snippet/dockerContainersList.html | 359 +++++++++++++++++----- 4 files changed, 294 insertions(+), 77 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 2375adb..9260d20 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -72,6 +72,8 @@ ENV WEBROOT="./www" VOLUME [ "/opt/zoraxy/config/" ] +LABEL com.imuslab.zoraxy.container-identifier="Zoraxy" + ENTRYPOINT [ "/opt/zoraxy/entrypoint.sh" ] HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 CMD nc -vz 127.0.0.1 $PORT || exit 1 diff --git a/docker/README.md b/docker/README.md index 74126a8..38629cd 100644 --- a/docker/README.md +++ b/docker/README.md @@ -19,6 +19,7 @@ Once setup, access the webui at `http://:8000` to configure Zoraxy. Cha docker run -d \ --name zoraxy \ --restart unless-stopped \ + --add-host=host.docker.internal:host-gateway \ -p 80:80 \ -p 443:443 \ -p 8000:8000 \ @@ -47,6 +48,8 @@ services: - /path/to/zoraxy/plugin/:/opt/zoraxy/plugin/ - /var/run/docker.sock:/var/run/docker.sock - /etc/localtime:/etc/localtime + extra_hosts: + - "host.docker.internal:host-gateway" environment: FASTGEOIP: "true" ``` @@ -68,6 +71,11 @@ services: | `/var/run/docker.sock` | Docker socket. Used for additional functionality with Zoraxy. | | `/etc/localtime` | Localtime. Set to ensure the host and container are synchronized. | +### Extra Hosts +| Host | Details | +|:-|:-| +| `host.docker.internal:host-gateway` | Resolves host.docker.internal to the host’s gateway IP on the Docker bridge network, allowing containers to access services running on the host machine. | + ### Environment Variables are the same as those in [Start Parameters](https://github.com/tobychui/zoraxy?tab=readme-ov-file#start-paramters). diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ce348c8..f32b973 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -12,5 +12,7 @@ services: - /path/to/zoraxy/plugin/:/opt/zoraxy/plugin/ - /var/run/docker.sock:/var/run/docker.sock - /etc/localtime:/etc/localtime + extra_hosts: + - "host.docker.internal:host-gateway" environment: FASTGEOIP: "true" diff --git a/src/web/snippet/dockerContainersList.html b/src/web/snippet/dockerContainersList.html index c79a8c8..2eca23a 100644 --- a/src/web/snippet/dockerContainersList.html +++ b/src/web/snippet/dockerContainersList.html @@ -1,14 +1,14 @@ - + - +
@@ -26,35 +26,54 @@
+
- List of Docker Containers + Networked Containers
- Below is a list of all detected Docker containers currently running - on the system. + Containers sharing a network with Zoraxy.
+ Docker DNS based name resolution has to be supported by your + network.
-
-
+
+
+ + +
- From 0c753ae5316e4ddaaa20efa7669cee5adb3aa2c4 Mon Sep 17 00:00:00 2001 From: Tim Dreyer <74516735+eyerrock@users.noreply.github.com> Date: Fri, 25 Apr 2025 14:55:31 +0200 Subject: [PATCH 4/6] refactor: rephrased ui --- src/web/snippet/dockerContainersList.html | 33 ++++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/web/snippet/dockerContainersList.html b/src/web/snippet/dockerContainersList.html index 23f854d..5f8765c 100644 --- a/src/web/snippet/dockerContainersList.html +++ b/src/web/snippet/dockerContainersList.html @@ -17,21 +17,21 @@
- +
Show Containers with Unexposed Ports
@@ -39,11 +39,10 @@
- Networked Containers + Containers on Zoraxy's Networks
- Containers sharing a network with Zoraxy.
- Docker DNS based name resolution has to be supported by your - network. + These containers share a network with Zoraxy.
+ Your networks must support Docker DNS-based name resolution.
@@ -54,10 +53,10 @@ @@ -66,10 +65,10 @@ @@ -77,8 +76,10 @@
@@ -430,7 +431,7 @@ $elem.prop("checked", state === "true"); } } - + function saveCheckboxState(id, $elem) { localStorage.setItem(id, $elem.prop("checked")); } From 73e6530862f398a449a90a9df31d336dd19f3b7e Mon Sep 17 00:00:00 2001 From: Tim Dreyer <74516735+eyerrock@users.noreply.github.com> Date: Fri, 25 Apr 2025 15:49:04 +0200 Subject: [PATCH 5/6] fix: docker api client version negotiation --- src/mod/dockerux/docker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/dockerux/docker.go b/src/mod/dockerux/docker.go index 9a3d5ad..bdaa1ed 100644 --- a/src/mod/dockerux/docker.go +++ b/src/mod/dockerux/docker.go @@ -20,7 +20,7 @@ func (d *UXOptimizer) HandleDockerAvailable(w http.ResponseWriter, r *http.Reque } func (d *UXOptimizer) HandleDockerContainersList(w http.ResponseWriter, r *http.Request) { - apiClient, err := client.NewClientWithOpts(client.WithVersion("1.43")) + apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { d.SystemWideLogger.PrintAndLog("Docker", "Unable to create new docker client", err) utils.SendErrorResponse(w, "Docker client initiation failed") From a98d86a3036fd1adb02cb7082c15f8a8bdbba714 Mon Sep 17 00:00:00 2001 From: Tim Dreyer <74516735+eyerrock@users.noreply.github.com> Date: Sat, 26 Apr 2025 16:23:17 +0200 Subject: [PATCH 6/6] fix: unexposed containers with existing proxy rule --- src/web/snippet/dockerContainersList.html | 36 ++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/web/snippet/dockerContainersList.html b/src/web/snippet/dockerContainersList.html index 5f8765c..d5bf493 100644 --- a/src/web/snippet/dockerContainersList.html +++ b/src/web/snippet/dockerContainersList.html @@ -268,26 +268,28 @@ // add the container to the networked list, using it's name as address container.Ports.forEach((portObject) => { - // skip unexposed ports if the checkbox is not checked - if (!portObject.PublicPort && !$showUnexposed.is(":checked")) { - return; - } - const port = portObject.PublicPort || portObject.PrivatePort; const key = `${containerName}:${port}`; - if (existingTargets.has(key) && !existingEntries[key]) { - existingEntries[key] = { - name: containerName, - ip: containerName, - port, - }; - } else if (!networkedEntries[key]) { - networkedEntries[key] = { - name: containerName, - ip: containerName, - port, - }; + // always include existing proxy-rule targets + if (existingTargets.has(key)) { + if (!existingEntries[key]) { + existingEntries[key] = { + name: containerName, + ip: containerName, + port, + }; + } + } + // otherwise, include only if exposed or checkbox is checked + else if (portObject.PublicPort || $showUnexposed.is(":checked")) { + if (!networkedEntries[key]) { + networkedEntries[key] = { + name: containerName, + ip: containerName, + port, + }; + } } }); });