From 45b5f8d7e2ca8079dbf815d5b0417e20c3dcd48d Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Wed, 3 Jun 2026 11:51:55 +0800 Subject: [PATCH] Fix Docker container status detection on node creation When a Docker container is created (e.g., when loading a project), the node status should reflect the actual container state. Previously, the node status was always set to 'stopped' even if the container was already running. This fix checks the container state after creation and updates the node status accordingly: - If container is running: status = 'started' - If container is paused: status = 'suspended' - If container is exited: status = 'stopped' (default) This ensures that project.is_running() correctly detects running Docker containers when attempting to export/duplicate a project, fixing the issue where running Docker nodes were not detected and prompted for shutdown. --- gns3server/compute/docker/docker_vm.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gns3server/compute/docker/docker_vm.py b/gns3server/compute/docker/docker_vm.py index 988d61cf3..393b21581 100644 --- a/gns3server/compute/docker/docker_vm.py +++ b/gns3server/compute/docker/docker_vm.py @@ -587,6 +587,20 @@ class DockerVM(BaseNode): log.info(f"CPU limit set to {self._cpus} CPUs") if self._memory > 0: log.info(f"Memory limit set to {self._memory} MB") + + # Check if the container is already running and update the node status accordingly + # This can happen when the server restarts and the container continues running + try: + state = await self._get_container_state() + if state == "running": + self.status = "started" + log.info(f"Docker container '{self._name}' is already running") + elif state == "paused": + self.status = "suspended" + log.info(f"Docker container '{self._name}' is paused") + except DockerError as e: + log.warning(f"Could not check container state for '{self._name}': {e}") + return True def _format_env(self, variables, env):