MCPcopy
hub / github.com/docker/compose / runPostStartHooksOnEvent

Method runPostStartHooksOnEvent

pkg/compose/run.go:93–120  ·  pkg/compose/run.go::composeService.runPostStartHooksOnEvent

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)

Source from the content-addressed store, hash-verified

91// runPostStartHooksOnEvent listens for the container's start event and executes
92// post_start lifecycle hooks once the container is running.
93func (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
122func (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

Callers 1

RunOneOffContainerMethod · 0.95

Calls 6

apiClientMethod · 0.95
runHookMethod · 0.95
EventsMethod · 0.65
DoneMethod · 0.65
ErrMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected