Skip to content

Commit

Permalink
Don't exit on container destroy events
Browse files Browse the repository at this point in the history
Fixes docker#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
cleanup up. I believe all that needs doing in this case is to ignore the
error. Another approach might be to check for the destroy event before
calling ContainerInspect.

Signed-off-by: Stephen Thirlwall <[email protected]>
  • Loading branch information
sdt committed Oct 31, 2021
1 parent 4cb6ace commit baa7ca9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/compose/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (s *composeService) watchContainers(ctx context.Context, projectName string
Consumer: func(event api.Event) error {
inspected, err := s.apiClient.ContainerInspect(ctx, event.Container)
if err != nil {
if (event.Status == "destroy") {
// This container can't be inspected, because it's gone.
// Its already been removed from the watched map.
return nil
}
return err
}
container := moby.Container{
Expand Down

0 comments on commit baa7ca9

Please sign in to comment.