in daemon/list.go [248:365]
func includeContainerInList(container *container.Container, ctx *listContext) iterationAction {
// Do not include container if it's in the list before the filter container.
// Set the filter container to nil to include the rest of containers after this one.
if ctx.beforeFilter != nil {
if container.ID == ctx.beforeFilter.ID {
ctx.beforeFilter = nil
}
return excludeContainer
}
// Stop iteration when the container arrives to the filter container
if ctx.sinceFilter != nil {
if container.ID == ctx.sinceFilter.ID {
return stopIteration
}
}
// Do not include container if it's stopped and we're not filters
// FIXME remove the ctx.beforContainer and ctx.sinceContainer part of the condition for 1.12 as --since and --before are deprecated
if !container.Running && !ctx.All && ctx.Limit <= 0 && ctx.beforeContainer == nil && ctx.sinceContainer == nil {
return excludeContainer
}
// Do not include container if the name doesn't match
if !ctx.filters.Match("name", container.Name) {
return excludeContainer
}
// Do not include container if the id doesn't match
if !ctx.filters.Match("id", container.ID) {
return excludeContainer
}
// Do not include container if any of the labels don't match
if !ctx.filters.MatchKVList("label", container.Config.Labels) {
return excludeContainer
}
// Do not include container if isolation doesn't match
if excludeContainer == excludeByIsolation(container, ctx) {
return excludeContainer
}
// FIXME remove this for 1.12 as --since and --before are deprecated
if ctx.beforeContainer != nil {
if container.ID == ctx.beforeContainer.ID {
ctx.beforeContainer = nil
}
return excludeContainer
}
// FIXME remove this for 1.12 as --since and --before are deprecated
if ctx.sinceContainer != nil {
if container.ID == ctx.sinceContainer.ID {
return stopIteration
}
}
// Stop iteration when the index is over the limit
if ctx.Limit > 0 && ctx.idx == ctx.Limit {
return stopIteration
}
// Do not include container if its exit code is not in the filter
if len(ctx.exitAllowed) > 0 {
shouldSkip := true
for _, code := range ctx.exitAllowed {
if code == container.ExitCode && !container.Running {
shouldSkip = false
break
}
}
if shouldSkip {
return excludeContainer
}
}
// Do not include container if its status doesn't match the filter
if !ctx.filters.Match("status", container.State.StateString()) {
return excludeContainer
}
if ctx.filters.Include("volume") {
volumesByName := make(map[string]*volume.MountPoint)
for _, m := range container.MountPoints {
if m.Name != "" {
volumesByName[m.Name] = m
} else {
volumesByName[m.Source] = m
}
}
volumeExist := fmt.Errorf("volume mounted in container")
err := ctx.filters.WalkValues("volume", func(value string) error {
if _, exist := container.MountPoints[value]; exist {
return volumeExist
}
if _, exist := volumesByName[value]; exist {
return volumeExist
}
return nil
})
if err != volumeExist {
return excludeContainer
}
}
if ctx.ancestorFilter {
if len(ctx.images) == 0 {
return excludeContainer
}
if !ctx.images[container.ImageID] {
return excludeContainer
}
}
return includeContainer
}