Beispiel #1
0
// Delete stopped containers
//
// We do this because Docker Swarm will account for stopped containers
// when using its affinity filter, where our semantics don't consider
// stopped containers in its scheduling decisions.
func delStopped(dk docker.Client) error {
	containers, err := dk.List(map[string][]string{"status": {"exited"}})
	if err != nil {
		return fmt.Errorf("error listing stopped containers: %s", err)
	}
	for _, dkc := range containers {
		// Stopped containers show up with a "/" in front of the name
		name := dkc.Name[1:]
		if err := dk.Remove(name); err != nil {
			log.WithFields(log.Fields{
				"name": name,
				"err":  err,
			}).Error("error removing container")
			continue
		}
	}
	return nil
}