Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

docker stack: text after an unbraced `$VAR` is dropped when it starts with `-`, `:-`, `?` or `:?`

未關閉 適合新手
#7,422 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@sebxt 已經在處理了。

開始於 2026年10月20日。

  • #7423 來自 @sebxt —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
87/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
docker, go
領域
cli

研究方向

從 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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

docker/cli 的其他 Issue

查看 docker/cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。