Skip to content

Commit f69dec2

Browse files
ras0219laurazard
authored andcommitted
Fixes docker#9403: Remove Named Pipes from volumeMounts
If named pipe mounts are added to the volumeMounts mapping, the docker daemon will report an error that it cannot be mapped. Signed-off-by: Robert Schumacher <[email protected]>
1 parent def189f commit f69dec2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pkg/compose/create.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,12 @@ func (s *composeService) buildContainerVolumes(ctx context.Context, p types.Proj
727727
binds := []string{}
728728
MOUNTS:
729729
for _, m := range mountOptions {
730+
if m.Type == mount.TypeNamedPipe {
731+
mounts = append(mounts, m)
732+
continue
733+
}
730734
volumeMounts[m.Target] = struct{}{}
731-
if m.Type == mount.TypeBind || m.Type == mount.TypeNamedPipe {
735+
if m.Type == mount.TypeBind {
732736
// `Mount` is preferred but does not offer option to created host path if missing
733737
// so `Bind` API is used here with raw volume string
734738
// see https://github.com/moby/moby/issues/43483

pkg/compose/create_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ func TestBuildBindMount(t *testing.T) {
4444
assert.Equal(t, mount.Type, mountTypes.TypeBind)
4545
}
4646

47+
func TestBuildNamedPipeMount(t *testing.T) {
48+
project := composetypes.Project{}
49+
volume := composetypes.ServiceVolumeConfig{
50+
Type: composetypes.VolumeTypeNamedPipe,
51+
Source: "\\\\.\\pipe\\docker_engine_windows",
52+
Target: "\\\\.\\pipe\\docker_engine",
53+
}
54+
mount, err := buildMount(project, volume)
55+
assert.NilError(t, err)
56+
assert.Equal(t, mount.Type, mountTypes.TypeNamedPipe)
57+
}
58+
4759
func TestBuildVolumeMount(t *testing.T) {
4860
project := composetypes.Project{
4961
Name: "myProject",
@@ -97,6 +109,11 @@ func TestBuildContainerMountOptions(t *testing.T) {
97109
Type: composetypes.VolumeTypeVolume,
98110
Target: "/var/myvolume2",
99111
},
112+
{
113+
Type: composetypes.VolumeTypeNamedPipe,
114+
Source: "\\\\.\\pipe\\docker_engine_windows",
115+
Target: "\\\\.\\pipe\\docker_engine",
116+
},
100117
},
101118
},
102119
},
@@ -128,18 +145,20 @@ func TestBuildContainerMountOptions(t *testing.T) {
128145
return mounts[i].Target < mounts[j].Target
129146
})
130147
assert.NilError(t, err)
131-
assert.Assert(t, len(mounts) == 2)
148+
assert.Assert(t, len(mounts) == 3)
132149
assert.Equal(t, mounts[0].Target, "/var/myvolume1")
133150
assert.Equal(t, mounts[1].Target, "/var/myvolume2")
151+
assert.Equal(t, mounts[2].Target, "\\\\.\\pipe\\docker_engine")
134152

135153
mounts, err = buildContainerMountOptions(project, project.Services[0], moby.ImageInspect{}, inherit)
136154
sort.Slice(mounts, func(i, j int) bool {
137155
return mounts[i].Target < mounts[j].Target
138156
})
139157
assert.NilError(t, err)
140-
assert.Assert(t, len(mounts) == 2)
158+
assert.Assert(t, len(mounts) == 3)
141159
assert.Equal(t, mounts[0].Target, "/var/myvolume1")
142160
assert.Equal(t, mounts[1].Target, "/var/myvolume2")
161+
assert.Equal(t, mounts[2].Target, "\\\\.\\pipe\\docker_engine")
143162
}
144163

145164
func TestGetDefaultNetworkMode(t *testing.T) {

0 commit comments

Comments
 (0)