lowestNumberedContainer returns the container with the lowest com.docker.compose.container-number label, so pre_start always targets the same replica regardless of the order the daemon returned them in. Panics on an empty slice; callers must guard.
(containers Containers)
| 37 | // same replica regardless of the order the daemon returned them in. |
| 38 | // Panics on an empty slice; callers must guard. |
| 39 | func lowestNumberedContainer(containers Containers) container.Summary { |
| 40 | pick := containers[0] |
| 41 | pickNum, _ := strconv.Atoi(pick.Labels[api.ContainerNumberLabel]) |
| 42 | for _, ctr := range containers[1:] { |
| 43 | num, _ := strconv.Atoi(ctr.Labels[api.ContainerNumberLabel]) |
| 44 | if num < pickNum { |
| 45 | pick, pickNum = ctr, num |
| 46 | } |
| 47 | } |
| 48 | return pick |
| 49 | } |
| 50 | |
| 51 | // runPreStart executes the service's pre_start hooks sequentially, in declared |
| 52 | // order. Each hook runs as an ephemeral container that shares the service |