@@ -259,7 +259,7 @@ func keys(input interface{}) (interface{}, error) {
259
259
260
260
vk := val .MapKeys ()
261
261
k := make ([]interface {}, val .Len ())
262
- for i , _ := range k {
262
+ for i := range k {
263
263
k [i ] = vk [i ].Interface ()
264
264
}
265
265
@@ -452,22 +452,37 @@ func newTemplate(name string) *template.Template {
452
452
return tmpl
453
453
}
454
454
455
+ func filterRunning (config Config , containers Context ) Context {
456
+ if config .IncludeStopped {
457
+ return containers
458
+ } else {
459
+ filteredContainers := Context {}
460
+ for _ , container := range containers {
461
+ if container .State .Running {
462
+ filteredContainers = append (filteredContainers , container )
463
+ }
464
+ }
465
+ return filteredContainers
466
+ }
467
+ }
468
+
455
469
func GenerateFile (config Config , containers Context ) bool {
470
+ filteredRunningContainers := filterRunning (config , containers )
456
471
filteredContainers := Context {}
457
472
if config .OnlyPublished {
458
- for _ , container := range containers {
473
+ for _ , container := range filteredRunningContainers {
459
474
if len (container .PublishedAddresses ()) > 0 {
460
475
filteredContainers = append (filteredContainers , container )
461
476
}
462
477
}
463
478
} else if config .OnlyExposed {
464
- for _ , container := range containers {
479
+ for _ , container := range filteredRunningContainers {
465
480
if len (container .Addresses ) > 0 {
466
481
filteredContainers = append (filteredContainers , container )
467
482
}
468
483
}
469
484
} else {
470
- filteredContainers = containers
485
+ filteredContainers = filteredRunningContainers
471
486
}
472
487
473
488
contents := executeTemplate (config .Template , filteredContainers )
0 commit comments