Merge pull request #1250 from docker/fix_logs

Filter out one_off containers on `compose logs`
This commit is contained in:
Guillaume Tardif 2021-02-05 11:36:49 +01:00 committed by GitHub
commit 42adbaeb8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -18,6 +18,8 @@ package compose
import (
"fmt"
"strconv"
"strings"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/docker/api/types/filters"
@ -44,6 +46,10 @@ func projectFilter(projectName string) filters.KeyValuePair {
return filters.Arg("label", fmt.Sprintf("%s=%s", projectLabel, projectName))
}
func oneOffFilter(oneOff bool) filters.KeyValuePair {
return filters.Arg("label", fmt.Sprintf("%s=%s", oneoffLabel, strings.Title(strconv.FormatBool(oneOff))))
}
func serviceFilter(serviceName string) filters.KeyValuePair {
return filters.Arg("label", fmt.Sprintf("%s=%s", serviceLabel, serviceName))
}

View File

@ -33,6 +33,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
list, err := s.apiClient.ContainerList(ctx, types.ContainerListOptions{
Filters: filters.NewArgs(
projectFilter(projectName),
oneOffFilter(false),
),
All: true,
})
@ -72,7 +73,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
if err != nil {
return err
}
w := getWriter(service, container.ID, consumer)
w := getWriter(service, container.Name[1:], consumer)
if container.Config.Tty {
_, err = io.Copy(w, r)
} else {