driver: only mount WSL libraries for local docker-container endpoints

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-04-08 09:39:11 +02:00
parent d61060eb95
commit 48fd4cb3cc
3 changed files with 28 additions and 15 deletions
+28 -13
View File
@@ -20,6 +20,7 @@ import (
"github.com/docker/buildx/util/imagetools"
"github.com/docker/buildx/util/progress"
"github.com/docker/cli/cli/context/docker"
contextstore "github.com/docker/cli/cli/context/store"
"github.com/docker/cli/opts"
"github.com/moby/buildkit/client"
mobyarchive "github.com/moby/go-archive"
@@ -153,19 +154,15 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
// is a local socket as requesting GPU on container builder creation
// is not enough when generating the CDI specification for GPU devices.
// https://github.com/docker/buildx/pull/3320
if os.Getenv("WSL_DISTRO_NAME") != "" {
if cm, err := d.ContextStore.GetMetadata(d.DockerContext); err == nil {
if epm, err := docker.EndpointFromContext(cm); err == nil && isSocket(epm.Host) {
wslLibPath := "/usr/lib/wsl"
if st, err := os.Stat(wslLibPath); err == nil && st.IsDir() {
mounts = append(mounts, mount.Mount{
Type: mount.TypeBind,
Source: wslLibPath,
Target: wslLibPath,
ReadOnly: true,
})
}
}
if os.Getenv("WSL_DISTRO_NAME") != "" && hasLocalSocketEndpoint(d.EndpointAddr, d.ContextStore) {
wslLibPath := "/usr/lib/wsl"
if st, err := os.Stat(wslLibPath); err == nil && st.IsDir() {
mounts = append(mounts, mount.Mount{
Type: mount.TypeBind,
Source: wslLibPath,
Target: wslLibPath,
ReadOnly: true,
})
}
}
hc.Mounts = mounts
@@ -574,6 +571,24 @@ func getBuildkitFlags(initConfig driver.InitConfig) []string {
return flags
}
func hasLocalSocketEndpoint(endpoint string, contextStore contextstore.Reader) bool {
if isSocket(endpoint) {
return true
}
if contextStore == nil {
return false
}
cm, err := contextStore.GetMetadata(endpoint)
if err != nil {
return false
}
epm, err := docker.EndpointFromContext(cm)
if err != nil {
return false
}
return isSocket(epm.Host)
}
func isSocket(addr string) bool {
switch proto, _, _ := strings.Cut(addr, "://"); proto {
case "unix", "npipe", "fd":
-1
View File
@@ -31,7 +31,6 @@ type InitConfig struct {
Name string
EndpointAddr string
DockerAPI dockerclient.APIClient
DockerContext string
ContextStore store.Reader
BuildkitdFlags []string
Files map[string][]byte