Skip to content

Commit 06219b0

Browse files
committed
chore: print container logs on start error
1 parent 285ede7 commit 06219b0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/start/start.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
"text/template"
1313
"time"
1414

15+
"github.com/docker/docker/api/types"
1516
"github.com/docker/docker/api/types/container"
17+
"github.com/docker/docker/pkg/stdcopy"
1618
"github.com/docker/go-connections/nat"
1719
"github.com/jackc/pgx/v4"
1820
"github.com/spf13/afero"
@@ -481,6 +483,22 @@ func waitForServiceReady(ctx context.Context, started []string) error {
481483
return len(started) == 0
482484
}
483485
if !reset.RetryEverySecond(ctx, probe, 20*time.Second) {
486+
// Print container logs for easier debugging
487+
for _, container := range started {
488+
logs, err := utils.Docker.ContainerLogs(ctx, container, types.ContainerLogsOptions{
489+
ShowStdout: true,
490+
ShowStderr: true,
491+
})
492+
if err != nil {
493+
fmt.Fprintln(os.Stderr, err)
494+
continue
495+
}
496+
fmt.Fprintln(os.Stderr, container, "container logs:")
497+
if _, err := stdcopy.StdCopy(os.Stderr, os.Stderr, logs); err != nil {
498+
fmt.Fprintln(os.Stderr, err)
499+
}
500+
logs.Close()
501+
}
484502
return fmt.Errorf("%w: %v", errUnhealthy, started)
485503
}
486504
return nil

0 commit comments

Comments
 (0)