diff --git a/internal/dag/executor/docker.go b/internal/dag/executor/docker.go index 822839bd..4b61e76e 100644 --- a/internal/dag/executor/docker.go +++ b/internal/dag/executor/docker.go @@ -88,6 +88,13 @@ func (e *docker) Run() error { return err } + defer func() { + if e.autoRemove { + err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{}) + util.LogErr("docker executor: remove container", err) + } + }() + statusCh, errCh := cli.ContainerWait( ctx, resp.ID, container.WaitConditionNotRunning, ) @@ -112,11 +119,6 @@ func (e *docker) Run() error { _, err = stdcopy.StdCopy(e.stdout, e.stdout, out) util.LogErr("docker executor: stdcopy", err) - if e.autoRemove { - err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{}) - util.LogErr("docker executor: remove container", err) - } - return nil }