Merge pull request #9348 from ndeloof/attach_tty

get Tty from container to know adequate way to attach to
This commit is contained in:
Guillaume Lours 2022-04-04 14:44:07 +02:00 committed by GitHub
commit 8d815ff587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -48,7 +48,7 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
fmt.Printf("Attaching to %s\n", strings.Join(names, ", ")) fmt.Printf("Attaching to %s\n", strings.Join(names, ", "))
for _, container := range containers { for _, container := range containers {
err := s.attachContainer(ctx, container, listener, project) err := s.attachContainer(ctx, container, listener)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,13 +56,9 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
return containers, err 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] serviceName := container.Labels[api.ServiceLabel]
containerName := getContainerNameWithoutProject(container) containerName := getContainerNameWithoutProject(container)
service, err := project.GetService(serviceName)
if err != nil {
return err
}
listener(api.ContainerEvent{ listener(api.ContainerEvent{
Type: api.ContainerEventAttach, Type: api.ContainerEventAttach,
@ -78,7 +74,13 @@ func (s *composeService) attachContainer(ctx context.Context, container moby.Con
Line: line, 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 return err
} }

View File

@ -55,7 +55,7 @@ func (s *composeService) start(ctx context.Context, projectName string, options
eg.Go(func() error { eg.Go(func() error {
return s.watchContainers(context.Background(), project.Name, options.AttachTo, listener, attached, func(container moby.Container) 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)
}) })
}) })
} }