fix: refuse Docker node updates that recreate a running container

Updating any Docker node property destroys and recreates the container
(the route calls DockerVM.update() as soon as the property diff is
non-empty), so it discards everything written inside it. On a running
node that happened silently, as a side effect of an unrelated edit: the
user only saw the node restart.

Refuse the update while the container is up and say what stopping it is
for, like QEMU, IOU, Dynamips, VPCS, VirtualBox and VMware already do
for their own restart-requiring settings. The check runs before anything
is applied — a refused update leaves the node untouched — and only when
the PUT really changes a property, since Web clients send the whole node
back on every edit.

is_running() is not reusable for the question: it reports a paused
container as not running and stops crashed containers as a side effect,
so DockerVM gains is_up() for "running or paused".
This commit is contained in:
YueGuobin committed 2026-10-16 16:49:11 +08:00
1 parent 290c542afe
commit 1090a32bbb
3 files changed
+101 -7

No files matched your search

+15
View File
@@ -1395,6 +1395,21 @@ class DockerVM(DockerKernelDatapathMixin, BaseNode):
await self.stop()
return False
async def is_up(self):
"""
Checks if the container exists in a running or paused state.
Both mean the container holds live state that recreating it would
discard. is_running() is not usable for that question: it reports a
paused container as not running, and it stops a crashed container as
a side effect.
:returns: True or False
:rtype: bool
"""
return await self._get_container_state() in ("running", "paused")
async def restart(self):
"""
Restart this Docker container.