fix(docker): handle container name conflict automatically

When a Docker container with the same name already exists (e.g., from a
   previous crashed GNS3 session), Docker returns a 409 Conflict error
   when trying to create a new container with that name. This causes the
   project open operation to fail.

   This fix adds automatic cleanup of stale containers when encountering
   a name conflict:
   - Added DockerHttp409Error exception class
   - Updated http_query to detect 409 status codes
   - Modified create() to remove conflicting containers and retry

   Fixes the issue where opening a project fails with:
   "Docker has returned an error: 409 Conflict. The container name
   '/GNS3.xxx' is already in use by container 'xxx'"
This commit is contained in:
YueGuobin committed 2026-02-27 23:35:11 +08:00
1 parent a0116902a6
commit ce90b2b92c
3 files changed
+30 -3

No files matched your search

+3 -1
View File
@@ -32,7 +32,7 @@ from gns3server.config import Config
from gns3server.utils.asyncio import locking
from gns3server.compute.base_manager import BaseManager
from gns3server.compute.docker.docker_vm import DockerVM
from gns3server.compute.docker.docker_error import DockerError, DockerHttp304Error, DockerHttp404Error
from gns3server.compute.docker.docker_error import DockerError, DockerHttp304Error, DockerHttp404Error, DockerHttp409Error
log = logging.getLogger(__name__)
@@ -240,6 +240,8 @@ class Docker(BaseManager):
raise DockerHttp304Error(f"Docker has returned an error: {response.status} {body}")
elif response.status == 404:
raise DockerHttp404Error(f"Docker has returned an error: {response.status} {body}")
elif response.status == 409:
raise DockerHttp409Error(f"Docker has returned an error: {response.status} {body}")
else:
raise DockerError(f"Docker has returned an error: {response.status} {body}")
return response