Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,6 @@ func bindRequiresMountAPI(bind *types.ServiceVolumeBind) bool {
return false
case !bool(bind.CreateHostPath):
return true
case bind.Propagation != "":
return true
case bind.Recursive != "":
return true
default:
Expand All @@ -1156,8 +1154,6 @@ func volumeRequiresMountAPI(vol *types.ServiceVolumeVolume) bool {
return true
case vol.Subpath != "":
return true
case vol.NoCopy:
return true
default:
return false
}
Expand Down
94 changes: 94 additions & 0 deletions pkg/compose/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,100 @@ volumes:
binds: []string{"my_volume:/data:ro"},
mounts: nil,
},
{
name: "bind mount propagation is part of the bind string",
yaml: `
services:
test:
volumes:
- type: bind
source: ./data
target: /data
bind:
propagation: rshared
`,
binds: []string{filepath.Join(pwd, "data") + ":/data:rw,rshared"},
mounts: nil,
},
{
name: "bind mount propagation, selinux and read only share the bind string",
yaml: `
services:
test:
volumes:
- type: bind
source: ./data
target: /data
read_only: true
bind:
selinux: z
propagation: rshared
`,
binds: []string{filepath.Join(pwd, "data") + ":/data:ro,z,rshared"},
mounts: nil,
},
{
name: "bind mount recursive requires the mount API",
yaml: `
services:
test:
volumes:
- type: bind
source: ./data
target: /data
bind:
recursive: disabled
`,
binds: nil,
mounts: []mountTypes.Mount{
{
Type: "bind",
Source: filepath.Join(pwd, "data"),
Target: "/data",
BindOptions: &mountTypes.BindOptions{CreateMountpoint: true, NonRecursive: true},
},
},
},
{
name: "mount volume nocopy is part of the bind string",
yaml: `
services:
test:
volumes:
- data:/data:nocopy
volumes:
data:
name: my_volume
`,
binds: []string{"my_volume:/data:rw,nocopy"},
mounts: nil,
},
{
name: "mount volume labels require the mount API",
yaml: `
services:
test:
volumes:
- type: volume
source: data
target: /data
volume:
labels:
tier: cache
volumes:
data:
name: my_volume
`,
binds: nil,
mounts: []mountTypes.Mount{
{
Type: "volume",
Source: "my_volume",
Target: "/data",
VolumeOptions: &mountTypes.VolumeOptions{Labels: map[string]string{"tier": "cache"}},
},
},
},
{
name: "mount volume subpath",
yaml: `
Expand Down
43 changes: 43 additions & 0 deletions pkg/e2e/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,49 @@ func BindMountSource(service, target, wantSource string) Check {
}
}

// BindMountPropagation expects the service's bind mount at target to have the
// given propagation, as the engine reports it for the running container.
func BindMountPropagation(service, target, want string) Check {
return Check{
name: fmt.Sprintf("service %q mount %q has propagation %s", service, target, want),
fn: func(ctx *CheckContext) error {
containers := ctx.curr.service(service)
if len(containers) == 0 {
return errors.New("service has no container")
}
for _, c := range containers {
res := icmd.RunCmd(ctx.scenario.cli.NewDockerCmd(ctx.scenario.t, "inspect", "--format", "{{json .Mounts}}", c.ID))
if res.ExitCode != 0 {
return fmt.Errorf("inspect failed: %s", res.Combined())
}
var mounts []struct {
Type string
Destination string
Propagation string
}
if err := json.Unmarshal([]byte(strings.TrimSpace(res.Stdout())), &mounts); err != nil {
return err
}
found := false
for _, m := range mounts {
if m.Type != "bind" || m.Destination != target {
continue
}
found = true
if m.Propagation != want {
return fmt.Errorf("container %s mount %s has propagation %q, want %q", c.Name, target, m.Propagation, want)
}
break
}
if !found {
return fmt.Errorf("container %s has no bind mount at %s", c.Name, target)
}
}
return nil
},
}
}

// LabelSet expects every container of the service to carry a non-empty label.
func LabelSet(service, key string) Check {
return Check{
Expand Down
18 changes: 18 additions & 0 deletions pkg/e2e/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,24 @@ func ContainerdImageStore(t testing.TB, c *CLI) string {
return ""
}

// SharedBindPropagation requires an engine that accepts the `rshared` bind
// propagation for a host directory, which needs the host path to sit on a
// shared mount: not the case when host paths reach the engine through the
// file-sharing mount of a VM (Docker Desktop), or when the root mount is
// private (docker-in-docker, rootless engines). It probes with the Mount API,
// so that a failure of the API a scenario goes through is not skipped.
func SharedBindPropagation(t testing.TB, c *CLI) string {
t.Helper()
res := icmd.RunCmd(c.NewDockerCmd(t, "run", "--rm",
"--mount", "type=bind,src="+t.TempDir()+",dst=/probe,bind-propagation=rshared",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] SharedBindPropagation probes the Mount API but the scenario now uses the bind-string path

The new SharedBindPropagation requirement function probes whether the engine accepts rshared propagation by running:

docker run --rm --mount type=bind,src=...,dst=/probe,bind-propagation=rshared alpine true

This uses the Mount API path. However, the PR removes bind.Propagation != "" from bindRequiresMountAPI, so Docker Compose now sends propagation via the bind string (e.g. src:/data:rw,rshared) instead. The comment in the function even acknowledges the intent was to probe "the API a scenario goes through" — but that API just changed.

In practice both paths likely reach the same kernel mount --make-rshared syscall on Linux, so this is a low-probability failure: the probe could pass on an engine that silently ignores rshared in the bind-string form but accepts it in the Mount API form (or rejects it differently), causing the test to run and fail unexpectedly instead of being skipped. Updating the probe to use docker run -v <src>:<dst>:rshared would align it with what the scenario actually exercises, and fix the now-stale comment.

Confidence Score
🟡 moderate 67/100

"alpine", "true"))
if res.ExitCode != 0 {
reason, _, _ := strings.Cut(strings.TrimSpace(res.Combined()), "\n")
return "the engine does not support the rshared propagation here: " + reason
}
return ""
}

// EngineAPIVersionAtLeast requires a minimum Engine API version (for example
// "1.56"), the unit in which the daemon's features are versioned.
func EngineAPIVersionAtLeast(minimum string) Requirement {
Expand Down
19 changes: 19 additions & 0 deletions pkg/e2e/testdata/TestVolumeOptionsAreApplied/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
app:
image: alpine
command: sleep infinity
init: true
volumes:
- type: bind
source: ./data
target: /data
bind:
propagation: rshared
- type: volume
source: cache
target: /media
volume:
nocopy: true

volumes:
cache:
Empty file.
41 changes: 41 additions & 0 deletions pkg/e2e/volume_options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build e2e

/*
Copyright 2026 Docker Compose CLI authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"testing"
"time"
)

// bind.propagation and volume.nocopy can be written in a `-v` string, so they
// do not need the Mount API of the engine. Whatever API carries them, the
// engine must apply them: this pins the effect, not the mechanism.
func TestVolumeOptionsAreApplied(t *testing.T) {
NewScenario(t, "a bind propagation and a volume nocopy must take effect in the container").
Requires(SharedBindPropagation).
Step("up starts the service with both options",
ComposeCmd("up", "-d"),
Eventually(ServiceState("app", "running"), 10*time.Second)).
Step("the bind mount has the requested propagation",
ComposeCmd("ps"),
BindMountPropagation("app", "/data", "rshared")).
Step("the volume was not filled with the content of the image",
ComposeCmd("ps"),
ExecOutputContains("app", `[ -z "$(ls -A /media)" ] && echo media-not-copied`, "media-not-copied"))
}
Loading