From 4693177e4b91d3a4c32ad178a106b817e942e750 Mon Sep 17 00:00:00 2001 From: gorkem-bwl Date: Fri, 29 Aug 2025 00:27:01 -0400 Subject: [PATCH] feat: add Docker container monitoring by name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update Docker monitoring to support both container names and IDs - Maintain backward compatibility with existing container ID monitoring - Add logic to find containers by name (with or without "/" prefix) - Update frontend UI labels and placeholders to reflect name/ID support - Update instructions to clarify both name and ID are supported Resolves user request: "It would be great if we could monitor docker containers by name and not just ID - given that the ID changes when containers are taken down for any reason" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- client/src/locales/en.json | 6 +++--- .../service/infrastructure/networkService.js | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 991f57d72..79a5ce4e8 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -440,7 +440,7 @@ "uptimeGeneralInstructions": { "http": "Enter the URL or IP to monitor (e.g., https://example.com/ or 192.168.1.100) and add a clear display name that appears on the dashboard.", "ping": "Enter the IP address or hostname to ping (e.g., 192.168.1.100 or example.com) and add a clear display name that appears on the dashboard.", - "docker": "Enter the Docker ID of your container. Docker IDs must be the full 64 char Docker ID. You can run docker inspect to get the full container ID.", + "docker": "Enter the Docker container name or ID. You can use either the container name (e.g., my-app) or the container ID (full 64-char ID or short ID).", "port": "Enter the URL or IP of the server, the port number and a clear display name that appears on the dashboard.", "game": "Enter the IP address or hostname and the port number to ping (e.g., 192.168.1.100 or example.com) and choose game type." }, @@ -1014,9 +1014,9 @@ }, "monitorType": { "docker": { - "label": "Container ID", + "label": "Container Name/ID", "namePlaceholder": "My Container", - "placeholder": "abcd1234" + "placeholder": "my-app or abcd1234" }, "http": { "label": "URL to monitor", diff --git a/server/src/service/infrastructure/networkService.js b/server/src/service/infrastructure/networkService.js index 72a117e74..1d8125be9 100644 --- a/server/src/service/infrastructure/networkService.js +++ b/server/src/service/infrastructure/networkService.js @@ -254,12 +254,23 @@ class NetworkService { }); const containers = await docker.listContainers({ all: true }); - const containerExists = containers.some((c) => c.Id.startsWith(monitor.url)); - if (!containerExists) { + + // Find container by ID (original behavior) or by name (new feature) + let targetContainer = containers.find((c) => { + // Check if monitor.url matches container ID (partial match) + if (c.Id.startsWith(monitor.url)) { + return true; + } + // Check if monitor.url matches any container name + // Container names are stored as ["/container-name"] in the Names array + return c.Names.some((name) => name === `/${monitor.url}` || name === monitor.url); + }); + + if (!targetContainer) { throw new Error(this.stringService.dockerNotFound); } - const container = docker.getContainer(monitor.url); + const container = docker.getContainer(targetContainer.Id); const { response, responseTime, error } = await this.timeRequest(() => container.inspect()); const dockerResponse = {