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 摘要。