buildMountOptions warns "should not define `bind` option" for named volumes carrying only an SELinux relabel flag, which compose itself consumes

未关闭 适合新手
#14,435 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
docker, docker-compose, go
领域
cli

调研方向

从 buildMountOptions() 开始,该函数在 mount 的类型为 volume 且 Bind 非 nil 时触发警告。检查 buildContainerVolumes() 和 toBindString() 如何为命名卷使用 v.Bind.SELinux,使警告只跳过 Bind 仅设置 SELinux 的情况。对于 propagation 和 create_host_path 等其他 Bind 字段,保留警告。完成标准是:带 z/Z 的命名卷挂载不产生警告,而带其他 Bind 字段的卷挂载仍会警告,并由 buildMountOptions 的测试覆盖。

由索引模型根据 Issue 内容生成。

描述

Description

A named-volume mount written with the documented short syntax vol:/path:z
canonicalises to type: volume + bind: {selinux: z}; bind.selinux is the
compose model's only slot for a relabel flag (volume: {selinux: z} is a schema
error, so there is no long-syntax alternative). buildMountOptions() then warns
unconditionally on volume.Type != VolumeTypeBind && volume.Bind != nil,
so every such mount emits a warning on every container create.

The warning is a false positive here, because compose itself consumes the
option it is warning about
: two functions later buildContainerVolumes()
routes plain named-volume mounts through the legacy HostConfig.Binds string
API via toBindString(), which appends v.Bind.SELinux (the modern Mounts
API cannot express relabels). Support for bind.selinux on named volumes was
added deliberately in compose-spec/compose-go#213 (fixing #9072, where the
flags were silently dropped). So the configuration is correct, compose honours
it, and the user is told it is wrong.

Steps to reproduce
services:
  probe:
    image: busybox:latest
    command: ["true"]
    volumes:
      - probevol:/data:z,rw
volumes:
  probevol:

docker compose up prints, once per z/Z-flagged named-volume mount per create:

time="..." level=warning msg="mount of type `volume` should not define `bind` option"

docker inspect confirms the flag was honoured:
Binds: ["proj_probevol:/data:rw,z"].

Expected

No warning when the bind: struct on a type: volume mount sets only
selinux, since that field is both the sole supported spelling and one compose
acts on. A bind: struct setting other fields (propagation,
create_host_path) on a volume mount should keep warning.

Impact

On SELinux-enforcing hosts the flags are load-bearing, so the warning cannot be
avoided by dropping them, and --log-level error suppresses all warnings rather
than this one. Deployment tooling ends up filtering the line out of compose's
stderr. It also breaks machine-readable output for downstream consumers:
ansible-collections/community.docker#846 is the same line failing an event
parser.

Versions

Reproduced on Compose v5.1.3 / Engine 29.4.1 (2026-07-19) and Compose v5.5.0 /
Engine 29.7.2 (2026-09-06). buildMountOptions() on main is unchanged.

主要语言
Go
星标
38.9k
派生
6k
平均合并
2 天 22 小时
30 天内合并 PR
81

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

docker/compose 的其他 Issue

查看 docker/compose 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。