Skip to content

Commit 20e3958

Browse files
committed
fix: -container-filter should override the env var
1 parent 615f63a commit 20e3958

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Environment Variables:
157157
DOCKER_CERT_PATH - directory path containing key.pem, cert.pem and ca.pem
158158
DOCKER_TLS_VERIFY - enable client TLS verification
159159
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.
160+
Filters supplied through this variable are ignored if -container-filter is provided.
161161
```
162162

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

cmd/docker-gen/main.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Environment Variables:
8787
DOCKER_CERT_PATH - directory path containing key.pem, cert.pem and ca.pem
8888
DOCKER_TLS_VERIFY - enable client TLS verification
8989
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.
90+
Filters supplied through this variable are ignored if -container-filter is provided.
9191
`)
9292
println(`For more information, see https://github.com/nginx-proxy/docker-gen`)
9393
}
@@ -152,20 +152,11 @@ func initFlags() {
152152
flag.Usage = usage
153153
flag.Parse()
154154

155-
// override containerFilter with DOCKER_CONTAINER_FILTERS environment variable
156-
if filtersEnvVar, found := os.LookupEnv("DOCKER_CONTAINER_FILTERS"); found && filtersEnvVar != "" {
157-
var nonBlankFilters []string
158-
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 {
159157
for filter := range strings.SplitSeq(filtersEnvVar, ",") {
160-
if strings.TrimSpace(filter) != "" {
161-
nonBlankFilters = append(nonBlankFilters, filter)
162-
}
163-
}
164-
165-
if len(nonBlankFilters) > 0 {
166-
containerFilter = make(mapstringslice)
167-
for _, filter := range nonBlankFilters {
168-
containerFilter.Set(filter)
158+
if trimmedFilter := strings.TrimSpace(filter); trimmedFilter != "" {
159+
containerFilter.Set(trimmedFilter)
169160
}
170161
}
171162
}

0 commit comments

Comments
 (0)