@@ -233,7 +233,7 @@ func keys(input interface{}) (interface{}, error) {
233233
234234 vk := val .MapKeys ()
235235 k := make ([]interface {}, val .Len ())
236- for i , _ := range k {
236+ for i := range k {
237237 k [i ] = vk [i ].Interface ()
238238 }
239239
@@ -425,22 +425,37 @@ func newTemplate(name string) *template.Template {
425425 return tmpl
426426}
427427
428+ func filterRunning (config Config , containers Context ) Context {
429+ if config .IncludeStopped {
430+ return containers
431+ } else {
432+ filteredContainers := Context {}
433+ for _ , container := range containers {
434+ if container .State .Running {
435+ filteredContainers = append (filteredContainers , container )
436+ }
437+ }
438+ return filteredContainers
439+ }
440+ }
441+
428442func GenerateFile (config Config , containers Context ) bool {
443+ filteredRunningContainers := filterRunning (config , containers )
429444 filteredContainers := Context {}
430445 if config .OnlyPublished {
431- for _ , container := range containers {
446+ for _ , container := range filteredRunningContainers {
432447 if len (container .PublishedAddresses ()) > 0 {
433448 filteredContainers = append (filteredContainers , container )
434449 }
435450 }
436451 } else if config .OnlyExposed {
437- for _ , container := range containers {
452+ for _ , container := range filteredRunningContainers {
438453 if len (container .Addresses ) > 0 {
439454 filteredContainers = append (filteredContainers , container )
440455 }
441456 }
442457 } else {
443- filteredContainers = containers
458+ filteredContainers = filteredRunningContainers
444459 }
445460
446461 contents := executeTemplate (config .Template , filteredContainers )
0 commit comments