浏览代码

fix: return correct exit code with `--exit-code-from` (#11715)

Nicolas De loof 1 年之前
父节点
当前提交
c9e070f0f6
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 5 3
      pkg/compose/printer.go
  2. 1 0
      pkg/compose/start.go

+ 5 - 3
pkg/compose/printer.go

@@ -138,9 +138,11 @@ func (p *printer) Run(cascade api.Cascade, exitCodeFrom string, stopFn func() er
 					if cascade == api.CascadeStop && exitCodeFrom == "" {
 						exitCodeFrom = event.Service
 					}
-					if exitCodeFrom == event.Service {
-						exitCode = event.ExitCode
-					}
+				}
+
+				if exitCodeFrom == event.Service && (event.Type == api.ContainerEventExit || event.Type == api.ContainerEventStopped) {
+					// Container was interrupted or exited, let's capture exit code
+					exitCode = event.ExitCode
 				}
 				if len(containers) == 0 {
 					// Last container terminated, done

+ 1 - 0
pkg/compose/start.go

@@ -268,6 +268,7 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
 						Container: name,
 						ID:        container.ID,
 						Service:   service,
+						ExitCode:  inspected.State.ExitCode,
 					})
 				}