Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/compose/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,19 @@ func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName
}
return moby.Container{}, fmt.Errorf("service %q is not running", serviceName)
}

// Sort by container number first, then put one-off containers at the end
sort.Slice(containers, func(i, j int) bool {
x, _ := strconv.Atoi(containers[i].Labels[api.ContainerNumberLabel])
y, _ := strconv.Atoi(containers[j].Labels[api.ContainerNumberLabel])
return x < y
numberLabelX, _ := strconv.Atoi(containers[i].Labels[api.ContainerNumberLabel])
numberLabelY, _ := strconv.Atoi(containers[j].Labels[api.ContainerNumberLabel])
IsOneOffLabelTrueX := containers[i].Labels[api.OneoffLabel] == "True"
IsOneOffLabelTrueY := containers[j].Labels[api.OneoffLabel] == "True"

if numberLabelX == numberLabelY {
return !IsOneOffLabelTrueX && IsOneOffLabelTrueY
}

return numberLabelX < numberLabelY
})
container := containers[0]
return container, nil
Expand Down