From c9fbb9ba9c844f5143111bc389f9edc45d49de11 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 4 Apr 2022 12:15:47 +0200 Subject: [PATCH] inspect container before attachment to use the adequate logic regarding TTY Signed-off-by: Nicolas De Loof --- pkg/compose/attach.go | 16 +++++++++------- pkg/compose/start.go | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/compose/attach.go b/pkg/compose/attach.go index b608e252e..42b815f3f 100644 --- a/pkg/compose/attach.go +++ b/pkg/compose/attach.go @@ -48,7 +48,7 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis fmt.Printf("Attaching to %s\n", strings.Join(names, ", ")) for _, container := range containers { - err := s.attachContainer(ctx, container, listener, project) + err := s.attachContainer(ctx, container, listener) if err != nil { return nil, err } @@ -56,13 +56,9 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis return containers, err } -func (s *composeService) attachContainer(ctx context.Context, container moby.Container, listener api.ContainerEventListener, project *types.Project) error { +func (s *composeService) attachContainer(ctx context.Context, container moby.Container, listener api.ContainerEventListener) error { serviceName := container.Labels[api.ServiceLabel] containerName := getContainerNameWithoutProject(container) - service, err := project.GetService(serviceName) - if err != nil { - return err - } listener(api.ContainerEvent{ Type: api.ContainerEventAttach, @@ -78,7 +74,13 @@ func (s *composeService) attachContainer(ctx context.Context, container moby.Con Line: line, }) }) - _, _, err = s.attachContainerStreams(ctx, container.ID, service.Tty, nil, w, w) + + inspect, err := s.dockerCli.Client().ContainerInspect(ctx, container.ID) + if err != nil { + return err + } + + _, _, err = s.attachContainerStreams(ctx, container.ID, inspect.Config.Tty, nil, w, w) return err } diff --git a/pkg/compose/start.go b/pkg/compose/start.go index a496e624f..19e88e61c 100644 --- a/pkg/compose/start.go +++ b/pkg/compose/start.go @@ -55,7 +55,7 @@ func (s *composeService) start(ctx context.Context, projectName string, options eg.Go(func() error { return s.watchContainers(context.Background(), project.Name, options.AttachTo, listener, attached, func(container moby.Container) error { - return s.attachContainer(ctx, container, listener, project) + return s.attachContainer(ctx, container, listener) }) }) }