docker/cli · error

invalid weight for device

Error message

invalid weight for device: %s

What it means

Returned by ValidateWeightDevice when strconv.ParseUint(v, 10, 16) fails on the weight part of --blkio-weight-device. The weight must be a base-10 integer that fits uint16 (0..65535); non-numeric, negative, decimal, or >65535 values fail here. (Range is further constrained to 10..1000, or 0 to unset — see 671.)

Solutions

  1. Use an integer in 10..1000 (or 0 to unset): '--blkio-weight-device=/dev/sda:200'.
  2. Strip any unit suffix or decimal point — weights are unitless integers.
  3. Cap the value at 1000 for a valid range (values 1001..65535 parse but fail the range check at 671).

Example fix

# before
docker run --blkio-weight-device=/dev/sda:1.5 ubuntu
# after
docker run --blkio-weight-device=/dev/sda:200 ubuntu
Defensive patterns

Strategy: validation

Validate before calling

// Weight must parse as a base-10 uint16 — check before the validator.
import ("strconv"; "strings")

func weightParses(s string) bool {
    _, v, ok := strings.Cut(s, ":")
    if !ok { return false }
    _, err := strconv.ParseUint(v, 10, 16)
    return err == nil
}

// if !weightParses(val) { return fmt.Errorf("weight must be an integer 0..65535, got %q", val) }

Try / catch

if _, err := opts.ValidateWeightDevice(val); err != nil {
    return err // invalid weight for device: <val>
}

Prevention

When it happens

Trigger: 'docker run --blkio-weight-device=/dev/sda:abc', '...=/dev/sda:-5', '...=/dev/sda:1.5', or '...=/dev/sda:70000' (overflows uint16).

Common situations: Passing a non-numeric weight, a fractional value, a value from a variable that resolved to empty/garbage, or a weight above 65535.

Related errors


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

Appendix: source

Thrown at opts/weightdevice.go:26

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

// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.
type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)

// ValidateWeightDevice validates that the specified string has a valid device-weight format.
func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) {
	k, v, ok := strings.Cut(val, ":")
	if !ok || k == "" {
		return nil, fmt.Errorf("bad format: %s", val)
	}
	// TODO(thaJeztah): should we really validate this on the client?
	if !strings.HasPrefix(k, "/dev/") {
		return nil, fmt.Errorf("bad format for device path: %s", val)
	}
	weight, err := strconv.ParseUint(v, 10, 16)
	if err != nil {
		return nil, fmt.Errorf("invalid weight for device: %s", val)
	}
	if weight > 0 && (weight < 10 || weight > 1000) {
		return nil, fmt.Errorf("invalid weight for device: %s", val)
	}

	return &blkiodev.WeightDevice{
		Path:   k,
		Weight: uint16(weight),
	}, nil
}

// WeightdeviceOpt defines a map of WeightDevices
type WeightdeviceOpt struct {
	values    []*blkiodev.WeightDevice
	validator ValidatorWeightFctType
}

// NewWeightdeviceOpt creates a new WeightdeviceOpt

View on GitHub (pinned to 4f84911bfe)