GoogleContainerTools/skaffold · error

compiling name match regex

Error message

compiling name match regex

What it means

getContainersCreated filters daemon container listings by name using a regex built from the container name: ^/?<name>(-\d+)?$. Compiling that regex only fails if the configured container/manifest name contains invalid regex metacharacters, so this error indicates a bad name string reaching the deployer.

Source

Thrown at pkg/skaffold/deploy/docker/deploy.go:451

	return csToDelete, nil
}

func (d *Deployer) getContainersCreated(ctx context.Context, img string) ([]container.Summary, error) {
	cl, err := d.client.ContainerList(ctx, client.ContainerListOptions{
		All:     true,
		Filters: client.Filters{}.Add("label", label.RunIDLabel).Add("name", img),
	})
	if err != nil {
		return nil, err
	}
	return d.filterByName(cl, img)
}

func (d *Deployer) filterByName(cl []container.Summary, cName string) ([]container.Summary, error) {
	nameMatchR, err := regexp.Compile(fmt.Sprintf("^/?%v(-\\d+)?$", cName))
	if err != nil {
		return nil, errors.Wrap(err, "compiling name match regex")
	}

	containers := []container.Summary{}
	for _, c := range cl {
		for _, n := range c.Names {
			if nameMatchR.MatchString(n) {
				containers = append(containers, c)
				break
			}
		}
	}

	return containers, nil
}

func (d *Deployer) networksToDelete(ctx context.Context, containers []container.Summary) ([]network.Summary, error) {
	ns, err := d.client.NetworkList(ctx, client.NetworkListOptions{
		Filters: client.Filters{}.Add("label", label.RunIDLabel),

View on GitHub (pinned to a1189de023)

Solutions

  1. Rename the artifact/deployment in skaffold.yaml to use only [a-zA-Z0-9-_] characters
  2. If a literal name with dots is needed, dots are actually valid regex; check for `(`, `)`, `[`, `]`, `+`, `*`, `?` and escape or remove them
  3. Inspect the wrapped compile error — it names the offending expression and position
  4. If the name is generated, sanitize it before it reaches the deploy config
  5. File/verify against skaffold if a legal Kubernetes name triggers this (potential bug: names should be regex-quoted)

Example fix

// before (skaffold.yaml)
artifacts:
  - image: my.app(v2)
// after
artifacts:
  - image: my-app-v2
Defensive patterns

Strategy: validation

Validate before calling

var nameRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._-]*$`)
func isRegexSafeName(name string) bool {
  if !nameRe.MatchString(name) { return false }
  _, err := regexp.Compile("^/?" + strings.ReplaceAll(regexp.QuoteMeta(name), "\\", "") + "(-\\d+)?$")
  return err == nil
}

Type guard

func safeName(s string) bool {
  for _, r := range s {
    if strings.ContainsRune("()[]{}*+?|^$.", r) && r != '.' { return false }
  }
  return len(s) > 0
}

Try / catch

containers, err := getContainersCreated(ctx, cl, img)
if err != nil && strings.Contains(err.Error(), "compiling name match regex") {
  return fmt.Errorf("artifact/image name %q contains regex metacharacters; rename it: %w", img, err)
}

Prevention

When it happens

Trigger: filterByName (called from getContainersCreated during Deploy) builds fmt.Sprintf("^/?%v(-\d+)?$", cName) and regexp.Compile fails because the artifact/deployment name contains characters like `(`, `[`, `+`, or other regex metacharacters.

Common situations: skaffold.yaml with an unusual artifact image or deploy name containing dots/parentheses/plus signs (e.g. `my.app+prod`); templated names injecting special characters; copy-pasted fully qualified names with slashes or tags.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/0903bdd3fe17703d. Report an issue: GitHub.