docker/cli · error

invalid generic-resource format

Error message

invalid generic-resource format `%s` expected `name=value`

What it means

Returned by ValidateSingleGenericResource (generic_resource_opts.go:21) when an entry in the --generic-resource list contains no `=` character. Generic resources must be expressed as `name=value` (e.g. `GPU=2`); the validator simply counts `=` occurrences and rejects anything with fewer than one.

Solutions

  1. Format each entry as name=value, e.g. `GPU=2`.
  2. Replace any `:` or space delimiters with `=`.
  3. Double-check compose-to-CLI translation of generic resource lists.

Example fix

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

Strategy: validation

Validate before calling

// Validate each generic-resource entry has the name=value shape.
func validateGenericResourceEntries(entries []string) error {
    for _, e := range entries {
        if strings.Count(e, "=") < 1 {
            return fmt.Errorf("invalid generic-resource format %q expected name=value", e)
        }
    }
    return nil
}

Type guard

// isNameValue reports whether entry matches the name=value shape.
func isNameValue(entry string) bool { return strings.Count(entry, "=") >= 1 }

Prevention

When it happens

Trigger: Passing `docker service create --generic-resource "GPU" ...` (missing `=value`), or a malformed entry like `GPU:2` using a colon instead of equals.

Common situations: Confusing the `=` delimiter with `:` (common from YAML/compose habits), forgetting the value, or passing a bare resource name.

Related errors


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

Appendix: source

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

import (
	"fmt"
	"strings"

	"github.com/docker/cli/cli/command/service/internal/genericresource"
	"github.com/moby/moby/api/types/swarm"
)

// GenericResource is a concept that a user can use to advertise user-defined
// resources on a node and thus better place services based on these resources.
// E.g: NVIDIA GPUs, Intel FPGAs, ...
// See https://github.com/moby/swarmkit/blob/de950a7ed842c7b7e47e9451cde9bf8f96031894/design/generic_resources.md

// ValidateSingleGenericResource validates that a single entry in the
// generic resource list is valid.
// i.e 'GPU=UID1' is valid however 'GPU:UID1' or 'UID1' isn't
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)
	}

View on GitHub (pinned to 4f84911bfe)