mirror of https://github.com/docker/compose.git
Merge pull request #1250 from docker/fix_logs
Filter out one_off containers on `compose logs`
This commit is contained in:
commit
42adbaeb8e
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue