slimtoolkit/slim · error

cant build service image - %s

Error message

cant build service image - %s

What it means

In Execution.PrepareService, when the service config has no pre-built Image name, the execution computes an image name and builds it — but only if ref.BuildImages is enabled and service.Build is configured. If neither holds, it returns 'cant build service image - %s': the library cannot obtain an image for this service because building is disabled or the service has no build section.

Source

Thrown at pkg/app/master/compose/execution.go:625

func (ref *Execution) PrepareService(ctx context.Context, name string) error {
	ref.logger.Debugf("Execution.PrepareService(%s)", name)
	serviceInfo, ok := ref.AllServices[name]
	if !ok {
		return fmt.Errorf("unknown service - %s", name)
	}

	service := serviceInfo.Config
	ref.logger.Debugf("Execution.PrepareService(%s): image=%s", name, service.Image)

	if service.Image == "" {
		imageName := fmt.Sprintf("%s_%s", ref.Project.Name, name)
		if ref.BuildImages && service.Build != nil {
			if err := buildImage(ctx, ref.apiClient, ref.BaseComposeDir, imageName, service.Build); err != nil {
				return err
			}
		} else {
			return fmt.Errorf("cant build service image - %s", name)
		}
	} else {
		found, err := HasImage(ref.apiClient, service.Image)
		if err != nil {
			return err
		}

		if found {
			return nil
		}

		//building image as if service.PullPolicy == types.PullPolicyBuild
		//todo: have an explicit flag for this behavior
		if ref.BuildImages && service.Build != nil {
			if err := buildImage(ctx, ref.apiClient, ref.BaseComposeDir, service.Image, service.Build); err != nil {
				return err
			}
		}

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Add an `image:` field to the service in docker-compose.yml so a pre-built image can be used, and ensure that image exists locally or in the registry
  2. Enable image building for the execution (set the BuildImages option / corresponding CLI flag) when services rely on `build:`
  3. Ensure the service defines a valid `build:` section (context, dockerfile) so the builder can run

Example fix

// before (docker-compose.yml)
services:
  worker:
    # no image, no build -> cant build service image
// after
services:
  worker:
    build:
      context: ./worker
    image: myapp/worker:latest
Defensive patterns

Strategy: validation

Validate before calling

func canObtainImage(exec *compose.Execution, svc types.ServiceConfig) error {
    if svc.Image != "" {
        return nil
    }
    if !exec.BuildImages {
        return fmt.Errorf("service %q has no image and building is disabled", svc.Name)
    }
    if svc.Build == nil {
        return fmt.Errorf("service %q has neither image nor build config", svc.Name)
    }
    return nil
}

Try / catch

if err := execution.PrepareService(ctx, svc); err != nil {
    if strings.HasPrefix(err.Error(), "cant build service image") {
        return fmt.Errorf("cannot obtain image for %q: enable build or set image: %w", svc, err)
    }
    return err
}

Prevention

When it happens

Trigger: PrepareService on a service whose config has service.Image == "" while (a) ref.BuildImages is false (image building disabled for this execution), or (b) service.Build is nil (no build context defined in the compose file).

Common situations: Starting a compose project that uses `build:` sections with image building disabled (e.g. a pull-only/deployment mode), a compose service missing both `image:` and `build:` keys, or a typo'd build key that leaves service.Build nil.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/7af77ddd62f1f2ee. Report an issue: GitHub.