Don't exit on container destroy events

Fixes #8747

When the event is a container destroy, calling ContainerInspect returns
an error, because the container no longer exists. This causes both
`docker-compose up` and `docker-compose logs -f` to exit when removing a
stopped container.

This container has already emitted its die event, and has already been
cleaned up. I believe all that needs doing in this case is to early-out.

Signed-off-by: Stephen Thirlwall <sdt@dr.com>
This commit is contained in:
Stephen Thirlwall 2021-10-30 17:29:25 +11:00 committed by Nicolas De loof
parent 72e4519cbf
commit a1f7be7b5c
1 changed files with 6 additions and 0 deletions

View File

@ -94,6 +94,12 @@ func (s *composeService) watchContainers(ctx context.Context, projectName string
err := s.Events(ctx, projectName, api.EventsOptions{
Services: services,
Consumer: func(event api.Event) error {
if (event.Status == "destroy") {
// This container can't be inspected, because it's gone.
// Its already been removed from the watched map.
return nil
}
inspected, err := s.apiClient.ContainerInspect(ctx, event.Container)
if err != nil {
return err