From cad2555dc02e3a444bf803abc7dfba9bba442db5 Mon Sep 17 00:00:00 2001 From: Roman Popa Date: Sun, 14 Jul 2024 16:10:08 +0200 Subject: [PATCH] Capture stderr from Docker container (#615) --- internal/dag/executor/docker.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/dag/executor/docker.go b/internal/dag/executor/docker.go index 4b61e76e9..69bfc3d98 100644 --- a/internal/dag/executor/docker.go +++ b/internal/dag/executor/docker.go @@ -95,6 +95,22 @@ func (e *docker) Run() error { } }() + out, err := cli.ContainerLogs( + ctx, resp.ID, types.ContainerLogsOptions{ + ShowStdout: true, + ShowStderr: true, + Follow: true, + }, + ) + if err != nil { + return err + } + + go func() { + _, err = stdcopy.StdCopy(e.stdout, e.stdout, out) + util.LogErr("docker executor: stdcopy", err) + }() + statusCh, errCh := cli.ContainerWait( ctx, resp.ID, container.WaitConditionNotRunning, ) @@ -109,16 +125,6 @@ func (e *docker) Run() error { } } - out, err := cli.ContainerLogs( - ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true}, - ) - if err != nil { - return err - } - - _, err = stdcopy.StdCopy(e.stdout, e.stdout, out) - util.LogErr("docker executor: stdcopy", err) - return nil }