@@ -114,6 +114,9 @@ type dockerClient struct {
114114 // tlsClientConfig is setup by newDockerClient and will be used and updated
115115 // by detectProperties(). Callers can edit tlsClientConfig.InsecureSkipVerify in the meantime.
116116 tlsClientConfig * tls.Config
117+ // registryProxyURL is the proxy URL from the registry configuration, if any.
118+ // It has the lowest priority and can be overridden by either DockerProxyURL or environment variables.
119+ registryProxyURL * url.URL
117120 // The following members are not set by newDockerClient and must be set by callers if needed.
118121 auth types.DockerAuthConfig
119122 registryToken string
@@ -262,18 +265,26 @@ func newDockerClient(sys *types.SystemContext, registry, reference string) (*doc
262265 return nil , err
263266 }
264267
265- // Check if TLS verification shall be skipped (default=false) which can
266- // be specified in the sysregistriesv2 configuration.
267- skipVerify := false
268+ // Fetch and load sysregistriesv2 configurations.
268269 reg , err := sysregistriesv2 .FindRegistry (sys , reference )
269270 if err != nil {
270271 return nil , fmt .Errorf ("loading registries: %w" , err )
271272 }
273+ skipVerify := false
274+ var registryProxyURL * url.URL
272275 if reg != nil {
273276 if reg .Blocked {
274277 return nil , fmt .Errorf ("registry %s is blocked in %s or %s" , reg .Prefix , sysregistriesv2 .ConfigPath (sys ), sysregistriesv2 .ConfigDirPath (sys ))
275278 }
279+ // Check if TLS verification shall be skipped (default=false).
276280 skipVerify = reg .Insecure
281+ // Set registry proxy.
282+ if reg .Proxy != "" {
283+ registryProxyURL , err = url .Parse (reg .Proxy )
284+ if err != nil {
285+ return nil , fmt .Errorf ("parsing proxy URL %q: %w" , reg .Proxy , err )
286+ }
287+ }
277288 }
278289 tlsClientConfig .InsecureSkipVerify = skipVerify
279290
@@ -287,6 +298,7 @@ func newDockerClient(sys *types.SystemContext, registry, reference string) (*doc
287298 registry : registry ,
288299 userAgent : userAgent ,
289300 tlsClientConfig : tlsClientConfig ,
301+ registryProxyURL : registryProxyURL ,
290302 tokenCache : map [string ]* bearerToken {},
291303 reportedWarnings : set .New [string ](),
292304 }, nil
@@ -968,6 +980,16 @@ func (c *dockerClient) detectPropertiesHelper(ctx context.Context) error {
968980 }
969981 tr := tlsclientconfig .NewTransport ()
970982 tr .TLSClientConfig = c .tlsClientConfig
983+ // Set registry-specific proxy with lowest priority, which can be overridden by environment variables.
984+ if c .registryProxyURL != nil {
985+ registryProxy := c .registryProxyURL
986+ tr .Proxy = func (req * http.Request ) (* url.URL , error ) {
987+ if envProxy , err := http .ProxyFromEnvironment (req ); err != nil || envProxy != nil {
988+ return envProxy , err
989+ }
990+ return registryProxy , nil
991+ }
992+ }
971993 // if set DockerProxyURL explicitly, use the DockerProxyURL instead of system proxy
972994 if c .sys != nil && c .sys .DockerProxyURL != nil {
973995 tr .Proxy = http .ProxyURL (c .sys .DockerProxyURL )
0 commit comments