浏览代码

Merge pull request #10181 from laurazard/fix-log-f

Fix issue where `compose logs` doesn't exit when all running containers have been stopped
Guillaume Lours 2 年之前
父节点
当前提交
a2899d5ff0
共有 2 个文件被更改,包括 7 次插入0 次删除
  1. 6 0
      pkg/compose/containers.go
  2. 1 0
      pkg/compose/logs.go

+ 6 - 0
pkg/compose/containers.go

@@ -99,6 +99,12 @@ func isService(services ...string) containerPredicate {
 	}
 }
 
+func isRunning() containerPredicate {
+	return func(c moby.Container) bool {
+		return c.State == "running"
+	}
+}
+
 func isNotService(services ...string) containerPredicate {
 	return func(c moby.Container) bool {
 		service := c.Labels[api.ServiceLabel]

+ 1 - 0
pkg/compose/logs.go

@@ -72,6 +72,7 @@ func (s *composeService) Logs(
 	}
 
 	if options.Follow {
+		containers = containers.filter(isRunning())
 		printer := newLogPrinter(consumer)
 		eg.Go(func() error {
 			_, err := printer.Run(false, "", nil)