Skip to content

Commit 2e92940

Browse files
committed
fix: remove stale container before start to prevent exit 125
1 parent f8b1b88 commit 2e92940

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

sandbox/container.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,24 @@ func (c *ContainerSandbox) Start(ctx context.Context) error {
5252
return nil
5353
}
5454

55+
name := c.containerName()
56+
57+
// Remove any stale container with the same name from a previous session
58+
exec.CommandContext(ctx, "docker", "rm", "-f", name).Run()
59+
5560
args := []string{
5661
"run", "-d", "--rm",
57-
"--name", c.containerName(),
62+
"--name", name,
5863
"-v", c.projectDir + ":/workspace",
5964
"-w", "/workspace",
6065
c.image,
6166
"sleep", "infinity",
6267
}
6368

6469
cmd := exec.CommandContext(ctx, "docker", args...)
65-
out, err := cmd.Output()
70+
out, err := cmd.CombinedOutput()
6671
if err != nil {
67-
return fmt.Errorf("container start failed: %w", err)
72+
return fmt.Errorf("container start failed: %s", strings.TrimSpace(string(out)))
6873
}
6974
c.containerID = strings.TrimSpace(string(out))
7075
c.running = true

0 commit comments

Comments
 (0)