docker/cli · error

invalid generic resource specification

Error message

invalid generic resource specification: %w

What it means

Returned by ParseGenericResources (generic_resource_opts.go:37) wrapping the error from genericresource.Parse. This fires when the input passes the superficial `=`-presence check but fails deeper parsing — typically because a discrete (numeric) resource value is not a valid integer, or the kind/value structure is malformed.

Solutions

  1. Use an integer value for discrete resources, e.g. `GPU=2`.
  2. Inspect the wrapped error (%w) for the precise parse reason.
  3. Trim whitespace and ensure exactly one `=` per entry.

Example fix

// before
docker service create --generic-resource "GPU=two" --name svc img
// after
docker service create --generic-resource "GPU=2" --name svc img
Defensive patterns

Strategy: validation

Validate before calling

// Pre-parse generic resources the same way the CLI does.
func validateGenericResources(entries []string) error {
    if _, err := genericresource.Parse(entries); err != nil {
        return fmt.Errorf("invalid generic resource specification: %w", err)
    }
    return nil
}

Prevention

When it happens

Trigger: Passing `--generic-resource "GPU=abc"` where the value is non-numeric for a discrete resource, or otherwise structurally invalid input that genericresource.Parse rejects.

Common situations: Requesting a count of GPUs/FPGAs with a non-integer value, extra whitespace breaking the parse, or mixing named and discrete syntax incorrectly.

Related errors


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

Appendix: source

Thrown at cli/command/service/generic_resource_opts.go:37

func ValidateSingleGenericResource(val string) (string, error) {
	if strings.Count(val, "=") < 1 {
		return "", fmt.Errorf("invalid generic-resource format `%s` expected `name=value`", val)
	}

	return val, nil
}

// ParseGenericResources parses an array of Generic resourceResources
// Requesting Named Generic Resources for a service is not supported this
// is filtered here.
func ParseGenericResources(value []string) ([]swarm.GenericResource, error) {
	if len(value) == 0 {
		return nil, nil
	}

	swarmResources, err := genericresource.Parse(value)
	if err != nil {
		return nil, fmt.Errorf("invalid generic resource specification: %w", err)
	}

	for _, res := range swarmResources {
		if res.NamedResourceSpec != nil {
			return nil, fmt.Errorf("invalid generic-resource request `%s=%s`, Named Generic Resources is not supported for service create or update",
				res.NamedResourceSpec.Kind, res.NamedResourceSpec.Value,
			)
		}
	}

	return swarmResources, nil
}

func buildGenericResourceMap(genericRes []swarm.GenericResource) (map[string]swarm.GenericResource, error) {
	m := make(map[string]swarm.GenericResource)

	for _, res := range genericRes {
		if res.DiscreteResourceSpec == nil {

View on GitHub (pinned to 4f84911bfe)