diff --git a/internal/dag/executor/docker.go b/internal/dag/executor/docker.go index 949bc9a4..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, ) @@ -96,7 +103,10 @@ func (e *docker) Run() error { if err != nil { return err } - case <-statusCh: + case status := <-statusCh: + if status.StatusCode != 0 { + return fmt.Errorf("exit status %v", status.StatusCode) + } } out, err := cli.ContainerLogs( @@ -109,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 }