@@ -40,32 +40,32 @@ func HandleDockerEvents(){
4040 return
4141 }
4242
43- for _ , c := range containers {
44-
45- cInspection , err := cli .ContainerInspect (ctx , c .ID )
46- logger .Infof ("status=container-from-list-begin, container=%s" , cInspection .Name )
47- if err != nil {
48- logger .Errorf ("status=inspect-error-at-list, container=%s, err=%v" , c .Names , err )
49- }
50- hostnames := getHostnames (cInspection )
51- putHostnames (defaultLogger , hostnames , cInspection )
52- logger .Infof ("status=container-from-list-success, container=%s, hostnames=%s" , cInspection .Name , hostnames )
53-
54- }
55-
5643 // more about events here: http://docs-stage.docker.com/v1.10/engine/reference/commandline/events/
5744 var eventFilter = filters .NewArgs ()
5845 eventFilter .Add ("event" , "start" )
59-
6046 eventFilter .Add ("event" , "die" )
6147 eventFilter .Add ("event" , "stop" )
6248
49+ // registering at events before get the list of actual containers, this way no one container will be missed #55
6350 body , err := cli .Events (ctx , types.EventsOptions { Filters : eventFilter })
6451 if err != nil {
6552 logger .Errorf ("status=error-to-attach-at-events-handler, solver=docker, err=%v" , err )
6653 return
6754 }
6855
56+ for _ , c := range containers {
57+
58+ cInspection , err := cli .ContainerInspect (ctx , c .ID )
59+ logger .Infof ("status=container-from-list-begin, container=%s" , cInspection .Name )
60+ if err != nil {
61+ logger .Errorf ("status=inspect-error-at-list, container=%s, err=%v" , c .Names , err )
62+ }
63+ hostnames := getHostnames (cInspection )
64+ putHostnames (defaultLogger , hostnames , cInspection )
65+ logger .Infof ("status=container-from-list-success, container=%s, hostnames=%s" , cInspection .Name , hostnames )
66+
67+ }
68+
6969 dec := json .NewDecoder (body )
7070 for {
7171
0 commit comments