runPostStartHooksOnEvent listens for the container's start event and executes post_start lifecycle hooks once the container is running.
(ctx context.Context, containerID string, service types.ServiceConfig, ctr container.Summary)
| 91 | // runPostStartHooksOnEvent listens for the container's start event and executes |
| 92 | // post_start lifecycle hooks once the container is running. |
| 93 | func (s *composeService) runPostStartHooksOnEvent(ctx context.Context, containerID string, service types.ServiceConfig, ctr container.Summary) error { |
| 94 | evtCtx, cancel := context.WithCancel(ctx) |
| 95 | defer cancel() |
| 96 | |
| 97 | res := s.apiClient().Events(evtCtx, client.EventsListOptions{ |
| 98 | Filters: make(client.Filters). |
| 99 | Add("type", "container"). |
| 100 | Add("container", containerID). |
| 101 | Add("event", string(events.ActionStart)), |
| 102 | }) |
| 103 | |
| 104 | // Wait for the container start event |
| 105 | select { |
| 106 | case <-evtCtx.Done(): |
| 107 | return evtCtx.Err() |
| 108 | case err := <-res.Err: |
| 109 | return err |
| 110 | case <-res.Messages: |
| 111 | // Container started, run hooks |
| 112 | } |
| 113 | |
| 114 | for _, hook := range service.PostStart { |
| 115 | if err := s.runHook(ctx, ctr, service, hook, nil); err != nil { |
| 116 | return err |
| 117 | } |
| 118 | } |
| 119 | return nil |
| 120 | } |
| 121 | |
| 122 | func (s *composeService) prepareRun(ctx context.Context, project *types.Project, opts api.RunOptions) (prepareRunResult, error) { |
| 123 | // Temporary implementation of use_api_socket until we get actual support inside docker engine |