docker stack: text after an unbraced `$VAR` is dropped when it starts with `-`, `:-`, `?` or `:?`
維護者通常 1 天內回覆
評估
研究方向
從 cli/compose/template/template.go 開始,檢查 defaultPattern,尤其是 named 和 braced 群組如何使用替換模式。使用提供的 compose 檔案和 docker stack config 重現問題,接著將結果與預期輸出及 docker compose config 比較;完成的標準是,未加大括號的變數後方文字保持原樣,而大括號修飾詞仍可正常運作。
由索引模型根據 Issue 內容生成。
描述
Description
In compose files used with docker stack config and docker stack deploy, an unbraced variable that is followed by -, :-, ? or :? is parsed as if it were the braced form with a modifier. The text after the variable is consumed as a default value or an error message.
For example nginx:$NGINX_VERSION-alpine is treated like nginx:${NGINX_VERSION-alpine}, and http://localhost:$PORT?ready=1 like http://localhost:${PORT?ready=1}.
The compose specification, docker compose, and shell parameter expansion only support modifiers in the braced form (${VAR:-default}); for $VAR the following characters are literal.
Reproduce
# c.yml
version: "3.8"
services:
web:
image: "nginx:$NGINX_VERSION-alpine"
healthcheck:
test: ["CMD", "wget", "-q", "http://localhost:$PORT?ready=1"]
$ NGINX_VERSION=1.27 PORT=8080 docker stack config -c c.yml
version: "3.8"
services:
web:
healthcheck:
test:
- CMD
- wget
- -q
- http://localhost:8080
image: nginx:1.27
With PORT unset, the command fails with required variable PORT is missing a value: ready=1.
Expected behavior
$ NGINX_VERSION=1.27 PORT=8080 docker stack config -c c.yml
...
- http://localhost:8080?ready=1
image: nginx:1.27-alpine
This is what docker compose config prints for the same file.
Root cause
In cli/compose/template/template.go the named group of defaultPattern uses the same sub-pattern as the braced group:
subst = "[_a-z][_a-z0-9]*(?::?[-?][^}]*)?"
...
"%s(?i:(?P<escaped>%s)|(?P<named>%s)|{(?P<braced>%s)}|(?P<invalid>))",
delimiter, delimiter, subst, subst,
so the optional (?::?[-?][^}]*) modifier suffix also matches after an unbraced name, and everything up to the next } (or the end of the string) is consumed.
Version
master at 52a2671034814f1ec6145aa8238c5fd4f92d5ee7
- 主要語言
- Go
- 星號
- 6.1k
- 分支
- 2.2k
- 平均合併
- 16 小時 8 分鐘
- 30 天內合併 PR
- 38
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
docker/cli 的其他 Issue
-
filename completion on `docker load -i`可能已有人在做 @cra 於 10 天前認領。 未關閉kind/feature status/0-triage
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
docker build treats uppercase HTTP(S) URLs as local paths可能已有人在做 @TanvirTian 於 17 天前認領。 未關閉kind/bug status/0-triage
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆
-
`docker context export` writes a truncated tar archive可能已有人在做 @2arian3 於 32 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 92/100
維護者通常 1 天內回覆
-
Truncating log lines at 75 characters makes them useless.可能已有人在做 @locker95 於 77 天前認領。 未關閉kind/bug status/0-triage
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
cli-plugins/hooks: max-message enforcement is off by one可能已有人在做 @fallintoplace 於 155 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
相似的 Issue
-
[doc-healer] DDUw improvement: retry integrity-filtered issue reads with direct single-item lookups未關閉automation documentation
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
bug needs-triage
難度 2/5 1-3 小時 新手友好度 80/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
containerd/containerd#14476 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 1/5 1-3 小時 新手友好度 82/100
Infisical/infisical#8987 · 1 則留言 ·
維護者通常 1 天內回覆
-
scan framework and scan control accept empty and whitespace-only policy names in Args validation可能已有人在做 @WKr1shna 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆