Skip to content

Commit 5eba42d

Browse files
committed
Correct Windows bind mount path
Signed-off-by: Xinfeng Liu <[email protected]>
1 parent 93e3cd5 commit 5eba42d

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"go.toolsEnvVars": {
3+
"GOOS": "windows"
4+
}
5+
}

libdocker/helpers.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ package libdocker
1818

1919
import (
2020
"fmt"
21+
"path/filepath"
2122
"runtime"
2223
"strconv"
2324
"strings"
2425
"time"
2526

27+
"github.com/docker/go-connections/nat"
28+
2629
dockerref "github.com/docker/distribution/reference"
2730
dockertypes "github.com/docker/docker/api/types"
2831
dockermount "github.com/docker/docker/api/types/mount"
29-
"github.com/docker/go-connections/nat"
3032
godigest "github.com/opencontainers/go-digest"
3133
"github.com/sirupsen/logrus"
3234
v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -217,14 +219,26 @@ func GenerateMountBindings(mounts []*v1.Mount, terminationMessagePath string, rt
217219
}
218220
result := make([]dockermount.Mount, 0, len(mounts))
219221
for _, m := range mounts {
220-
if runtime.GOOS == "windows" && isSingleFileMount(m.HostPath, m.ContainerPath, terminationMessagePath) {
221-
logrus.Debugf("skipping mount :%s:%s", m.HostPath, m.ContainerPath)
222-
continue
222+
hostPath, containerPath := m.HostPath, m.ContainerPath
223+
if runtime.GOOS == "windows" {
224+
if isSingleFileMount(hostPath, containerPath, terminationMessagePath) {
225+
logrus.Debugf("skipping mount :%s:%s", m.HostPath, m.ContainerPath)
226+
continue
227+
}
228+
if !isNamedPipe(hostPath) {
229+
hostPath = filepath.Clean(hostPath)
230+
}
231+
if !isNamedPipe(containerPath) {
232+
containerPath = filepath.Clean(containerPath)
233+
if containerPath[0] == '\\' {
234+
containerPath = "C:" + containerPath
235+
}
236+
}
223237
}
224238
bind := dockermount.Mount{
225239
Type: dockermount.TypeBind,
226-
Source: m.HostPath,
227-
Target: m.ContainerPath,
240+
Source: hostPath,
241+
Target: containerPath,
228242
BindOptions: &dockermount.BindOptions{
229243
CreateMountpoint: true,
230244
},
@@ -334,3 +348,7 @@ func MakePortsAndBindings(
334348
}
335349
return exposedPorts, portBindings
336350
}
351+
352+
func isNamedPipe(s string) bool {
353+
return strings.HasPrefix(s, `\\.\pipe\`)
354+
}

0 commit comments

Comments
 (0)