Skip to content

fix(volumes_from): keep the ro/rw access mode of a service reference - #14267

Open
breken-ai wants to merge 1 commit into
docker:mainfrom
breken-ai:fix-volumes-from-access-mode
Open

breken-ai wants to merge 1 commit into
docker:mainfrom
breken-ai:fix-volumes-from-access-mode

Conversation

@breken-ai

Copy link
Copy Markdown

What I did

volumes_from entries that point at a service lost their access mode. resolveVolumeFrom (pkg/compose/service_containers.go) swaps the service name for the id of the service's container. It split the entry on : and kept only the name, so this:

services:
  data:
    image: redis:7-alpine
    command: ["sleep", "3600"]
    volumes: [shared:/shared]
  reader:
    image: redis:7-alpine
    command: ["sleep", "3600"]
    volumes_from:
      - data:ro
volumes:
  shared:

reached the engine as VolumesFrom: ["<id>"], and reader could write to data's volumes. The container:<name>:ro form lost its mode the same way (only spec[1] was kept).

The fix keeps the :ro / :rw suffix when it resolves both forms.

Behaviour with docker compose up -d, then docker inspect reader and touch /shared/x inside reader (engine 27.5.1):

build HostConfig.VolumesFrom /shared RW touch /shared/x
main @ 32bddfc ["cf1d…f683"] true succeeds
this branch ["e4b9…f0e9:ro"] false Read-only file system

Tests:

  • New TestResolveVolumeFromKeepsAccessMode covers db:ro, container:external:ro, db:rw, db and container:other. It fails on main ("db-ctr-id" vs "db-ctr-id:ro", and "external" vs "external:ro") and passes here.
  • go test ./pkg/... ./cmd/... passes, except 3 pkg/watch tests (TestGitBranchSwitch, TestWatchBrokenLink, TestWatchCountInnerFile) that fail the same way on main on macOS.
  • golangci-lint run --build-tags e2e ./pkg/compose/... (v2.13.2, the version pinned in the Dockerfile): 0 issues.

Note: services that declare :ro/:rw get a different resolved config hash, so the next up recreates them once. That is how their mounts get the mode they asked for.

This PR includes AI_AGENT_DISCLOSURE.md as AGENTS.md asks. The ai-disclosure gate blocks merge until a human reviews the change and removes the file.

Related issue

No open issue found. #1750 and #1188 asked for :ro support in volumes_from, which compose v1 had.

(not mandatory) A picture of a cute animal, if possible in relation to what you did

🐢 (a turtle's shell is read-only too)

🤖 Generated with Claude Code

resolveVolumeFrom replaces each volumes_from service name with the id of
the service's container, but it split the entry on ":" and kept only the
name, dropping the access mode. `volumes_from: [db:ro]` was sent to the
engine as `<id>`, so the volumes were mounted read-write, and
`container:name:ro` lost its mode the same way.

Keep the mode suffix when resolving both forms.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: breken-ai <312387581+breken-ai@users.noreply.github.com>
@breken-ai
breken-ai requested review from a team as code owners September 25, 2026 23:31
@breken-ai
breken-ai requested review from glours and ndeloof September 25, 2026 23:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant