Skip to content

Commit e0d2383

Browse files
committed
feat: container filters environment variable
1 parent f58442d commit e0d2383

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ Environment Variables:
156156
DOCKER_HOST - default value for -endpoint
157157
DOCKER_CERT_PATH - directory path containing key.pem, cert.pem and ca.pem
158158
DOCKER_TLS_VERIFY - enable client TLS verification
159+
DOCKER_CONTAINER_FILTERS - comma separated list of container filters for inclusion by docker-gen.
160+
Filters supplied through this variable override filters supplied through the -container-filter options.
159161
```
160162

161163
If no `<dest>` file is specified, the output is sent to stdout. Mainly useful for debugging.

cmd/docker-gen/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Environment Variables:
8686
DOCKER_HOST - default value for -endpoint
8787
DOCKER_CERT_PATH - directory path containing key.pem, cert.pem and ca.pem
8888
DOCKER_TLS_VERIFY - enable client TLS verification
89+
DOCKER_CONTAINER_FILTERS - comma separated list of container filters for inclusion by docker-gen.
90+
Filters supplied through this variable override filters supplied through the -container-filter options.
8991
`)
9092
println(`For more information, see https://github.com/nginx-proxy/docker-gen`)
9193
}
@@ -121,6 +123,13 @@ func initFlags() {
121123
"include stopped containers. Bypassed when providing a container status filter (-container-filter status=foo).")
122124
flag.Var(&containerFilter, "container-filter",
123125
"container filter for inclusion by docker-gen. You can pass this option multiple times to combine filters with AND. https://docs.docker.com/engine/reference/commandline/ps/#filter")
126+
// override containerFilter with DOCKER_CONTAINER_FILTERS environment variable
127+
if filters := strings.Split(os.Getenv("DOCKER_CONTAINER_FILTERS"), ","); len(filters) > 0 && filters[0] != "" {
128+
containerFilter = make(mapstringslice)
129+
for _, filter := range filters {
130+
containerFilter.Set(filter)
131+
}
132+
}
124133

125134
// Command notification options
126135
flag.StringVar(&notifyCmd, "notify", "", "run command after template is regenerated (e.g `restart xyz`)")

0 commit comments

Comments
 (0)