Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#7,422 コメント 0 件 リアクション 0 件 担当者 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
平均マージ
15時間 11分
マージ済み PR(30日)
42

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker/cli のほかの issue

docker/cli の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。