Skip to content

Commit 901d6c4

Browse files
authored
feat: container filters environment variable (#700)
1 parent dccdd3a commit 901d6c4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-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 are ignored if -container-filter is provided.
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: 11 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 are ignored if -container-filter is provided.
8991
`)
9092
println(`For more information, see https://github.com/nginx-proxy/docker-gen`)
9193
}
@@ -149,6 +151,15 @@ func initFlags() {
149151

150152
flag.Usage = usage
151153
flag.Parse()
154+
155+
// set containerFilter with DOCKER_CONTAINER_FILTERS if it's set and no -container-filter option was provided
156+
if filtersEnvVar, found := os.LookupEnv("DOCKER_CONTAINER_FILTERS"); found && len(containerFilter) == 0 {
157+
for filter := range strings.SplitSeq(filtersEnvVar, ",") {
158+
if trimmedFilter := strings.TrimSpace(filter); trimmedFilter != "" {
159+
containerFilter.Set(trimmedFilter)
160+
}
161+
}
162+
}
152163
}
153164

154165
func main() {

0 commit comments

Comments
 (0)