docker/cli · error

invalid count ( ): value must be either "all" or an integer

Error message

invalid count (%s): value must be either "all" or an integer: %w

What it means

parseCount accepts exactly the literal string "all" (mapped to -1) or a base-10 integer. Anything else — a float, a spelled-out number, "all2", or non-numeric text — fails strconv.Atoi and is wrapped here with the underlying NumError. The GPU count has a very narrow grammar.

Solutions

  1. Use an integer: --gpus 2, or the key form --gpus count=2.
  2. Use the literal --gpus all to request every GPU.
  3. Strip stray characters/whitespace from the value before parsing.
  4. Validate the field with parseCount (or strconv.Atoi + "all" check) before invoking Set.

Example fix

# before
docker run --gpus 1.5 myimg

# after
docker run --gpus 2 myimg   # or --gpus all
Defensive patterns

Strategy: validation

Validate before calling

// Validate a GPU count string the same way parseCount does.
func validGpuCount(s string) error {
    if s == "all" {
        return nil
    }
    if _, err := strconv.Atoi(s); err != nil {
        return fmt.Errorf(`count must be "all" or an integer, got %q`, s)
    }
    return nil
}

Prevention

When it happens

Trigger: Passing --gpus a count that is neither "all" nor an integer, e.g. --gpus 1.5, --gpus two, or --gpus count=1.5.

Common situations: Typo in the count; passing a fractional GPU count; misunderstanding that only "all" or an int are allowed.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/c906a1b9cfde2054. Report an issue: GitHub.

Appendix: source

Thrown at opts/gpus.go:28

	"github.com/moby/moby/api/types/container"
)

// GpuOpts is a Value type for parsing mounts
type GpuOpts struct {
	values []container.DeviceRequest
}

func parseCount(s string) (int, error) {
	if s == "all" {
		return -1, nil
	}
	i, err := strconv.Atoi(s)
	if err != nil {
		var numErr *strconv.NumError
		if errors.As(err, &numErr) {
			err = numErr.Err
		}
		return 0, fmt.Errorf(`invalid count (%s): value must be either "all" or an integer: %w`, s, err)
	}
	return i, nil
}

// Set a new mount value
//
//nolint:gocyclo
func (o *GpuOpts) Set(value string) error {
	csvReader := csv.NewReader(strings.NewReader(value))
	fields, err := csvReader.Read()
	if err != nil {
		return err
	}

	req := container.DeviceRequest{}

	seen := map[string]struct{}{}
	// Set writable as the default

View on GitHub (pinned to 4f84911bfe)