You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add support for DOCKER_CUSTOM_HEADERS env-var (experimental)
This environment variable allows for setting additional headers
to be sent by the client. Headers set through this environment
variable are added to headers set through the config-file (through
the HttpHeaders field).
This environment variable can be used in situations where headers
must be set for a specific invocation of the CLI, but should not
be set by default, and therefore cannot be set in the config-file.
WARNING: If both config and environment-variable are set, the environment
variable currently overrides all headers set in the configuration file.
This behavior may change in a future update, as we are considering the
environment variable to be appending to existing headers (and to only
override headers with the same name).
Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 6638deb)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
returnerrdefs.InvalidParameter(errors.Errorf("failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs", envOverrideHTTPHeaders))
181
+
}
182
+
iflen(fields) ==0 {
183
+
returnnil
184
+
}
185
+
186
+
env:=map[string]string{}
187
+
for_, kv:=rangefields {
188
+
k, v, hasValue:=strings.Cut(kv, "=")
189
+
190
+
// Only strip whitespace in keys; preserve whitespace in values.
191
+
k=strings.TrimSpace(k)
192
+
193
+
ifk=="" {
194
+
returnerrdefs.InvalidParameter(errors.Errorf(`failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`, envOverrideHTTPHeaders, kv))
195
+
}
196
+
197
+
// We don't currently allow empty key=value pairs, and produce an error.
198
+
// This is something we could allow in future (e.g. to read value
199
+
// from an environment variable with the same name). In the meantime,
200
+
// produce an error to prevent users from depending on this.
201
+
if!hasValue {
202
+
returnerrdefs.InvalidParameter(errors.Errorf(`failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`, envOverrideHTTPHeaders, kv))
203
+
}
204
+
205
+
env[http.CanonicalHeaderKey(k)] =v
206
+
}
207
+
208
+
iflen(env) ==0 {
209
+
// We should probably not hit this case, as we don't skip values
210
+
// (only return errors), but we don't want to discard existing
211
+
// headers with an empty set.
212
+
returnnil
213
+
}
214
+
215
+
// TODO(thaJeztah): add a client.WithExtraHTTPHeaders() function to allow these headers to be _added_ to existing ones, instead of _replacing_
216
+
// see https://github.com/docker/cli/pull/5098#issuecomment-2147403871 (when updating, also update the WARNING in the function and env-var GoDoc)
|`DOCKER_API_VERSION`| Override the negotiated API version to use for debugging (e.g. `1.19`) |
123
123
|`DOCKER_CERT_PATH`| Location of your authentication keys. This variable is used both by the `docker` CLI and the [`dockerd` daemon](https://docs.docker.com/reference/cli/dockerd/)|
124
124
|`DOCKER_CONFIG`| The location of your client configuration files. |
125
125
|`DOCKER_CONTENT_TRUST_SERVER`| The URL of the Notary server to use. Defaults to the same URL as the registry. |
126
126
|`DOCKER_CONTENT_TRUST`| When set Docker uses notary to sign and verify images. Equates to `--disable-content-trust=false` for build, create, pull, push, run. |
127
127
|`DOCKER_CONTEXT`| Name of the `docker context` to use (overrides `DOCKER_HOST` env var and default context set with `docker context use`) |
128
+
|`DOCKER_CUSTOM_HEADERS`| (Experimental) Configure [custom HTTP headers](#custom-http-headers) to be sent by the client. Headers must be provided as a comma-separated list of `name=value` pairs. This is the equivalent to the `HttpHeaders` field in the configuration file. |
128
129
|`DOCKER_DEFAULT_PLATFORM`| Default platform for commands that take the `--platform` flag. |
129
130
|`DOCKER_HIDE_LEGACY_COMMANDS`| When set, Docker hides "legacy" top-level commands (such as `docker rm`, and `docker pull`) in `docker help` output, and only `Management commands` per object-type (e.g., `docker container`) are printed. This may become the default in a future release. |
130
131
|`DOCKER_HOST`| Daemon socket to connect to. |
@@ -281,6 +282,10 @@ sent from the Docker client to the daemon. Docker doesn't try to interpret or
281
282
understand these headers; it simply puts them into the messages. Docker does
282
283
not allow these headers to change any headers it sets for itself.
283
284
285
+
Alternatively, use the `DOCKER_CUSTOM_HEADERS`[environment variable](#environment-variables),
286
+
which is available in v27.1 and higher. This environment-variable is experimental,
287
+
and its exact behavior may change.
288
+
284
289
#### Credential store options
285
290
286
291
The property `credsStore` specifies an external binary to serve as the default
0 commit comments