docker/compose · warning · ErrNoResources

no resources

Error message

no resources

What it means

api.ErrNoResources is returned when an operation ends up selecting zero resources to act on. In this repo, pkg/compose/remove.go and pkg/compose/kill.go return it when no container matches the selection, and cmd/compose/remove.go plus cmd/compose/kill.go special-case it with errors.Is to print a friendlier 'no resource ... to remove/kill' style message instead of a hard error.

Source

Thrown at pkg/api/errors.go:47

var (
	// ErrNotFound is returned when an object is not found
	ErrNotFound = errors.New("not found")
	// ErrAlreadyExists is returned when an object already exists
	ErrAlreadyExists = errors.New("already exists")
	// ErrForbidden is returned when an operation is not permitted
	ErrForbidden = errors.New("forbidden")
	// ErrUnknown is returned when the error type is unmapped
	ErrUnknown = errors.New("unknown")
	// ErrNotImplemented is returned when a backend doesn't implement an action
	ErrNotImplemented = errors.New("not implemented")
	// ErrUnsupportedFlag is returned when a backend doesn't support a flag
	ErrUnsupportedFlag = errors.New("unsupported flag")
	// ErrCanceled is returned when the command was canceled by user
	ErrCanceled = errors.New("canceled")
	// ErrParsingFailed is returned when a string cannot be parsed
	ErrParsingFailed = errors.New("parsing failed")
	// ErrNoResources is returned when operation didn't selected any resource
	ErrNoResources = errors.New("no resources")
)

// IsNotFoundError returns true if the unwrapped error is ErrNotFound
func IsNotFoundError(err error) bool {
	return errors.Is(err, ErrNotFound)
}

// IsAlreadyExistsError returns true if the unwrapped error is ErrAlreadyExists
func IsAlreadyExistsError(err error) bool {
	return errors.Is(err, ErrAlreadyExists)
}

// IsForbiddenError returns true if the unwrapped error is ErrForbidden
func IsForbiddenError(err error) bool {
	return errors.Is(err, ErrForbidden)
}

// IsUnknownError returns true if the unwrapped error is ErrUnknown

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Treat it as a no-op in scripts: check `docker compose ls` first, or accept this outcome as success for idempotent cleanup.
  2. Verify the project name/directory and that containers exist (docker compose ps -a) if removal was expected.
  3. In Go code, branch on errors.Is(err, api.ErrNoResources) and continue.

Example fix

# before
docker compose rm -f  # may error when nothing matches

# after (idempotent cleanup)
docker compose ps -aq | grep -q . && docker compose rm -f || echo 'nothing to remove'
Defensive patterns

Strategy: try-catch

Validate before calling

# skip teardown when nothing exists
docker compose ps -aq | grep -q . || { echo 'no containers; skipping'; exit 0; }

Type guard

func isNoResources(err error) bool { return errors.Is(err, api.ErrNoResources) }

Try / catch

if err := backend.Remove(ctx, project, opts); err != nil {
    if errors.Is(err, api.ErrNoResources) {
        return nil // nothing selected: treat as success for idempotent cleanup
    }
    return err
}

Prevention

When it happens

Trigger: `docker compose rm` or `docker compose kill` when the selection (service names, --status filters) matches no containers — e.g. project not created yet, already removed, or filtered to nothing.

Common situations: Cleanup scripts run repeatedly (idempotent teardown hitting an already-clean project); wrong -p project name; filters like status=running when everything is stopped.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/2aeaa4b79b8c9f1b. Report an issue: GitHub.