From f69dec2da820d6d4a80e564b6f119a188326a8da Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Sun, 24 Apr 2022 00:11:01 +0000 Subject: [PATCH] Fixes #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 --- pkg/compose/create.go | 6 +++++- pkg/compose/create_test.go | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pkg/compose/create.go b/pkg/compose/create.go index e0789d1fb..8801436fc 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -727,8 +727,12 @@ func (s *composeService) buildContainerVolumes(ctx context.Context, p types.Proj binds := []string{} MOUNTS: for _, m := range mountOptions { + if m.Type == mount.TypeNamedPipe { + mounts = append(mounts, m) + continue + } volumeMounts[m.Target] = struct{}{} - if m.Type == mount.TypeBind || m.Type == mount.TypeNamedPipe { + if m.Type == mount.TypeBind { // `Mount` is preferred but does not offer option to created host path if missing // so `Bind` API is used here with raw volume string // see https://github.com/moby/moby/issues/43483 diff --git a/pkg/compose/create_test.go b/pkg/compose/create_test.go index 7a0e95c6f..cdcc4ad61 100644 --- a/pkg/compose/create_test.go +++ b/pkg/compose/create_test.go @@ -44,6 +44,18 @@ func TestBuildBindMount(t *testing.T) { assert.Equal(t, mount.Type, mountTypes.TypeBind) } +func TestBuildNamedPipeMount(t *testing.T) { + project := composetypes.Project{} + volume := composetypes.ServiceVolumeConfig{ + Type: composetypes.VolumeTypeNamedPipe, + Source: "\\\\.\\pipe\\docker_engine_windows", + Target: "\\\\.\\pipe\\docker_engine", + } + mount, err := buildMount(project, volume) + assert.NilError(t, err) + assert.Equal(t, mount.Type, mountTypes.TypeNamedPipe) +} + func TestBuildVolumeMount(t *testing.T) { project := composetypes.Project{ Name: "myProject", @@ -97,6 +109,11 @@ func TestBuildContainerMountOptions(t *testing.T) { Type: composetypes.VolumeTypeVolume, Target: "/var/myvolume2", }, + { + Type: composetypes.VolumeTypeNamedPipe, + Source: "\\\\.\\pipe\\docker_engine_windows", + Target: "\\\\.\\pipe\\docker_engine", + }, }, }, }, @@ -128,18 +145,20 @@ func TestBuildContainerMountOptions(t *testing.T) { return mounts[i].Target < mounts[j].Target }) assert.NilError(t, err) - assert.Assert(t, len(mounts) == 2) + assert.Assert(t, len(mounts) == 3) assert.Equal(t, mounts[0].Target, "/var/myvolume1") assert.Equal(t, mounts[1].Target, "/var/myvolume2") + assert.Equal(t, mounts[2].Target, "\\\\.\\pipe\\docker_engine") mounts, err = buildContainerMountOptions(project, project.Services[0], moby.ImageInspect{}, inherit) sort.Slice(mounts, func(i, j int) bool { return mounts[i].Target < mounts[j].Target }) assert.NilError(t, err) - assert.Assert(t, len(mounts) == 2) + assert.Assert(t, len(mounts) == 3) assert.Equal(t, mounts[0].Target, "/var/myvolume1") assert.Equal(t, mounts[1].Target, "/var/myvolume2") + assert.Equal(t, mounts[2].Target, "\\\\.\\pipe\\docker_engine") } func TestGetDefaultNetworkMode(t *testing.T) {