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.
This commit is contained in:
YueGuobin 2026-06-03 11:51:55 +08:00
parent 1d7feaf994
commit 45b5f8d7e2
No known key found for this signature in database

View File

@ -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):