@@ -20,6 +20,7 @@ import (
2020 "github.com/docker/buildx/util/imagetools"
2121 "github.com/docker/buildx/util/progress"
2222 "github.com/docker/cli/cli/context/docker"
23+ contextstore "github.com/docker/cli/cli/context/store"
2324 "github.com/docker/cli/opts"
2425 "github.com/moby/buildkit/client"
2526 mobyarchive "github.com/moby/go-archive"
@@ -153,19 +154,15 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
153154 // is a local socket as requesting GPU on container builder creation
154155 // is not enough when generating the CDI specification for GPU devices.
155156 // https://github.com/docker/buildx/pull/3320
156- if os .Getenv ("WSL_DISTRO_NAME" ) != "" {
157- if cm , err := d .ContextStore .GetMetadata (d .DockerContext ); err == nil {
158- if epm , err := docker .EndpointFromContext (cm ); err == nil && isSocket (epm .Host ) {
159- wslLibPath := "/usr/lib/wsl"
160- if st , err := os .Stat (wslLibPath ); err == nil && st .IsDir () {
161- mounts = append (mounts , mount.Mount {
162- Type : mount .TypeBind ,
163- Source : wslLibPath ,
164- Target : wslLibPath ,
165- ReadOnly : true ,
166- })
167- }
168- }
157+ if os .Getenv ("WSL_DISTRO_NAME" ) != "" && hasLocalSocketEndpoint (d .EndpointAddr , d .ContextStore ) {
158+ wslLibPath := "/usr/lib/wsl"
159+ if st , err := os .Stat (wslLibPath ); err == nil && st .IsDir () {
160+ mounts = append (mounts , mount.Mount {
161+ Type : mount .TypeBind ,
162+ Source : wslLibPath ,
163+ Target : wslLibPath ,
164+ ReadOnly : true ,
165+ })
169166 }
170167 }
171168 hc .Mounts = mounts
@@ -574,6 +571,24 @@ func getBuildkitFlags(initConfig driver.InitConfig) []string {
574571 return flags
575572}
576573
574+ func hasLocalSocketEndpoint (endpoint string , contextStore contextstore.Reader ) bool {
575+ if isSocket (endpoint ) {
576+ return true
577+ }
578+ if contextStore == nil {
579+ return false
580+ }
581+ cm , err := contextStore .GetMetadata (endpoint )
582+ if err != nil {
583+ return false
584+ }
585+ epm , err := docker .EndpointFromContext (cm )
586+ if err != nil {
587+ return false
588+ }
589+ return isSocket (epm .Host )
590+ }
591+
577592func isSocket (addr string ) bool {
578593 switch proto , _ , _ := strings .Cut (addr , "://" ); proto {
579594 case "unix" , "npipe" , "fd" :
0 commit comments