Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#7,422 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@sebxt ci sta già lavorando.

Dal 20/10/2026.

  • #7423 di @sebxt — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
87/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, go
Ambito
cli

Direzione di ricerca

Inizia da cli/compose/template/template.go e analizza defaultPattern, in particolare il modo in cui i gruppi named e braced usano il pattern di sostituzione. Riproduci il problema con il file compose fornito e docker stack config, quindi confronta l'output atteso con docker compose config; il lavoro è completo quando il testo dopo le variabili senza parentesi graffe rimane letterale, mentre i modificatori tra parentesi graffe continuano a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Go
Stelle
6.1k
Fork
2.2k
Merge medio
15h 11m
PR unite (30g)
42

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di docker/cli

Tutte le issue di docker/cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.