From b192d06ec79a0e5a496c7b676d372989a5b48d21 Mon Sep 17 00:00:00 2001 From: Rob Murray Date: Tue, 9 Sep 2025 18:40:17 +0100 Subject: [PATCH] Remove network info from container when endpoint join fails Signed-off-by: Rob Murray --- daemon/container_operations.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon/container_operations.go b/daemon/container_operations.go index 4dbdc35103..f8712c04b1 100644 --- a/daemon/container_operations.go +++ b/daemon/container_operations.go @@ -735,10 +735,14 @@ func (daemon *Daemon) connectToNetwork(ctx context.Context, cfg *config.Config, } } }() - ctr.NetworkSettings.Networks[nwName] = endpointConfig delete(ctr.NetworkSettings.Networks, n.ID()) - + ctr.NetworkSettings.Networks[nwName] = endpointConfig + defer func() { + if retErr != nil { + delete(ctr.NetworkSettings.Networks, nwName) + } + }() if err := daemon.updateEndpointNetworkSettings(cfg, ctr, n, ep); err != nil { return err }