From 123dd83b51b5ba37f75e6fcc2f5b4ad0a963eb5e Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 3 May 2025 09:30:14 +0000 Subject: [PATCH] fix(docker): [ota] stop old container --- internal/docker/ota.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/docker/ota.go b/internal/docker/ota.go index 4c9d3661..4789d28c 100644 --- a/internal/docker/ota.go +++ b/internal/docker/ota.go @@ -256,6 +256,12 @@ func UpgradeStepTwo(ctx context.Context) (err error) { return errors.Wrap(err, "failed to rename old container") } + // Stop the old container + err = cli.ContainerStop(ctx, currentContainerName+OldSuffix, container.StopOptions{}) + if err != nil { + return errors.Wrap(err, "failed to stop old container") + } + // 3. Use the old config to create and start a new container with the updated image // Create new container with original config but using the new image newContainerEnv := oldContainerInfo.Config.Env @@ -302,6 +308,7 @@ func UpgradeStepTwo(ctx context.Context) (err error) { // Start the new container err = cli.ContainerStart(ctx, currentContainerName, container.StartOptions{}) if err != nil { + logger.Error("Failed to start new container:", err) // If startup fails, try to recover // First remove the failed new container removeErr := cli.ContainerRemove(ctx, currentContainerName, container.RemoveOptions{Force: true})