[BUG] Negative replica count in scale flags (docker compose scale / --scale) is accepted without validation

Aperta
#14,482 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@arsalanyavari ci sta già lavorando.

Dal 10/11/2026.

  • #14483 di @arsalanyavari — aperta

Valutazione

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

Direzione di ricerca

The report identifies the scale and up --scale CLI paths but names no source files or tests. Start by tracing how each command parses and validates replica counts, then find the corresponding tests. Done means both commands reject negative counts while accepting zero and positive counts; an open linked pull request is already addressing this issue.

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

Descrizione

kind/bug status/approved
Description

According to the Compose Specification, scale must be a non-negative integer (>= 0). The Compose file loader already enforces this and rejects negative scale: values in compose.yaml.

Additionally, the CLI properly validates non-numeric inputs — for instance, docker compose scale web=abc immediately returns:

invalid scale specifier: can't parse replica value as int: web=abc

However, when passing a negative replica count through the CLI flags, such as docker compose scale web=-1 or docker compose up --scale web=-1, the value is accepted without any validation error. The service is then assigned a negative replica count, which leads to unexpected behavior during convergence and container lifecycle handling.

The CLI should validate that the replica count is non-negative, consistent with the Compose Specification and with how the compose file loader treats negative scales.

Steps To Reproduce
  1. Create a minimal compose.yaml:
    services:
      web:
        image: alpine
    
  2. Attempt to scale the service with a negative replica count:
    docker compose scale web=-1
    
    Or:
    docker compose up --dry-run --scale web=-1
    
Observed Result
  • docker compose scale web=-1:

    [+] scale 1/1
     ✔ Network a_default Created                                                                                    0.0s
    service "web" has no container to start
    

    The negative value -1 is accepted without any validation error.

  • docker compose up --dry-run --scale web=-1:

    end of 'compose up' output, interactive run is not supported in dry-run mode
    

    The command finishes without warning or error regarding the negative replica count.

Compose Version
$ docker compose version
Docker Compose version v5.5.0
Docker Environment
Docker version 29.9.3, build 5457199aa5
Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.17.2
    Path:     /path/to/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.5.0
    Path:     /path/to/.docker/cli-plugins/docker-compose
Anything else?

No response

Lingua principale
Go
Stelle
38.9k
Fork
6k
Merge medio
2g 22h
PR unite (30g)
81

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/compose

Tutte le issue di docker/compose

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.