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

Offen
#14,482 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@arsalanyavari arbeitet bereits daran.

Seit 10.11.2026.

  • #14483 von @arsalanyavari — offen

Bewertung

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

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
Go
Sterne
38.9k
Forks
6k
Ø Merge
2 T. 22 Std.
Gemergte PRs (30 T.)
81

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

Alle Issues in docker/compose

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

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