Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen Anfängerfreundlich
#7,422 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@sebxt arbeitet bereits daran.

Seit 20.10.2026.

  • #7423 von @sebxt — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
87/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
docker, go
Bereich
cli

Rechercherichtung

Beginne in cli/compose/template/template.go und untersuche defaultPattern, insbesondere, wie die Gruppen named und braced das Substitutionsmuster verwenden. Reproduziere das Problem mit der bereitgestellten Compose-Datei und docker stack config, vergleiche dann die erwartete Ausgabe mit docker compose config; als erledigt gilt die Aufgabe, wenn Text nach nicht geklammerten Variablen wörtlich bleibt, während geklammerte Modifikatoren weiterhin funktionieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
Go
Sterne
6.1k
Forks
2.2k
Ø Merge
15 Std. 11 Min.
Gemergte PRs (30 T.)
42

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus docker/cli

Alle Issues in docker/cli

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.