diff --git a/cli/compose/convert/volume.go b/cli/compose/convert/volume.go index 38806d2972..c2bebe0731 100644 --- a/cli/compose/convert/volume.go +++ b/cli/compose/convert/volume.go @@ -122,6 +122,26 @@ func handleTmpfsToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e return result, nil } +func handleNpipeToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, error) { + result := createMountFromVolume(volume) + + if volume.Source == "" { + return mount.Mount{}, errors.New("invalid npipe source, source cannot be empty") + } + if volume.Volume != nil { + return mount.Mount{}, errors.New("volume options are incompatible with type npipe") + } + if volume.Tmpfs != nil { + return mount.Mount{}, errors.New("tmpfs options are incompatible with type npipe") + } + if volume.Bind != nil { + result.BindOptions = &mount.BindOptions{ + Propagation: mount.Propagation(volume.Bind.Propagation), + } + } + return result, nil +} + func convertVolumeToMount( volume composetypes.ServiceVolumeConfig, stackVolumes volumes, @@ -135,6 +155,8 @@ func convertVolumeToMount( return handleBindToMount(volume) case "tmpfs": return handleTmpfsToMount(volume) + case "npipe": + return handleNpipeToMount(volume) } - return mount.Mount{}, errors.New("volume type must be volume, bind, or tmpfs") + return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs or npipe") } diff --git a/cli/compose/convert/volume_test.go b/cli/compose/convert/volume_test.go index d29c3b6de2..5f5bd8aaab 100644 --- a/cli/compose/convert/volume_test.go +++ b/cli/compose/convert/volume_test.go @@ -41,7 +41,7 @@ func TestConvertVolumeToMountUnapprovedType(t *testing.T) { Target: "/foo/bar", } _, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) - assert.Error(t, err, "volume type must be volume, bind, or tmpfs") + assert.Error(t, err, "volume type must be volume, bind, tmpfs or npipe") } func TestConvertVolumeToMountConflictingOptionsBindInVolume(t *testing.T) { @@ -343,3 +343,19 @@ func TestConvertTmpfsToMountVolumeWithSource(t *testing.T) { _, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) assert.Error(t, err, "invalid tmpfs source, source must be empty") } + +func TestConvertVolumeToMountAnonymousNpipe(t *testing.T) { + config := composetypes.ServiceVolumeConfig{ + Type: "npipe", + Source: `\\.\pipe\foo`, + Target: `\\.\pipe\foo`, + } + expected := mount.Mount{ + Type: mount.TypeNamedPipe, + Source: `\\.\pipe\foo`, + Target: `\\.\pipe\foo`, + } + mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(expected, mount)) +} diff --git a/docs/reference/commandline/service_create.md b/docs/reference/commandline/service_create.md index 8fdb5297a1..36848a8241 100644 --- a/docs/reference/commandline/service_create.md +++ b/docs/reference/commandline/service_create.md @@ -271,7 +271,7 @@ metadata](https://docs.docker.com/engine/userguide/labels-custom-metadata/). Docker supports three different kinds of mounts, which allow containers to read from or write to files or directories, either on the host operating system, or on memory filesystems. These types are _data volumes_ (often referred to simply -as volumes), _bind mounts_, and _tmpfs_. +as volumes), _bind mounts_, _tmpfs_, and _named pipes_. A **bind mount** makes a file or directory on the host available to the container it is mounted within. A bind mount may be either read-only or @@ -291,6 +291,8 @@ You can back up or restore volumes using Docker commands. A **tmpfs** mounts a tmpfs inside a container for volatile data. +A **npipe** mounts a named pipe from the host into the container. + Consider a situation where your image starts a lightweight web server. You could use that image as a base image, copy in your website's HTML files, and package that into another image. Each time your website changed, you'd need to update @@ -312,21 +314,22 @@ volumes in a service: Description - types + type -

The type of mount, can be either volume, bind, or tmpfs. Defaults to volume if no type is specified. +

The type of mount, can be either volume, bind, tmpfs, or npipe. Defaults to volume if no type is specified.

src or source - for type=bind only> + for type=bind and type=npipe