GoogleContainerTools/skaffold · error

INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME

INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME

Error message

artifact %s has invalid container name '%s'

What it means

When a network mode references a container, the container name must match Docker's naming rules ^[a-zA-Z0-9][a-zA-Z0-9_.-]*$. validateDockerContainerExpression returns this actionable error (INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME) when the name contains illegal characters.

Source

Thrown at pkg/skaffold/schema/validation/validation.go:357

			},
		})
}

// validateDockerNetworkModeExpression makes sure that the network mode starts with "container:" followed by a valid container name
func validateDockerNetworkModeExpression(image string, expr string) error {
	id, err := extractContainerNameFromNetworkMode(expr)
	if err != nil {
		return err
	}
	return validateDockerContainerExpression(image, id)
}

// validateDockerContainerExpression makes sure that the container name pass in matches Docker's regular expression for containers
func validateDockerContainerExpression(image string, id string) error {
	containerRegExp := regexp.MustCompile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
	if !containerRegExp.MatchString(id) {
		errMsg := fmt.Sprintf("artifact %s has invalid container name '%s'", image, id)
		return sErrors.NewError(errors.New(errMsg),
			&proto.ActionableErr{
				Message: errMsg,
				ErrCode: proto.StatusCode_INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME,
				Suggestions: []*proto.Suggestion{
					{
						SuggestionCode: proto.SuggestionCode_FIX_DOCKER_NETWORK_CONTAINER_NAME,
						Action:         "Please fix the docker network container name and try again",
					},
				},
			})
	}
	return nil
}

// validateDockerNetworkMode makes sure that networkMode is one of `bridge`, `none`, `container:<name|id>`, or `host` if set.
func validateDockerNetworkMode(cfg *parser.SkaffoldConfigEntry, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) {
	for i, a := range artifacts {
		if a.DockerArtifact == nil || a.DockerArtifact.NetworkMode == "" {

View on GitHub (pinned to a1189de023)

Solutions

  1. Rename the referenced container (or the reference in skaffold.yaml) to a Docker-legal name: start with a letter/digit, then letters, digits, '_', '.', '-'.
  2. Follow the actionable suggestion FIX_DOCKER_NETWORK_CONTAINER_NAME shown with the error.
  3. Verify the actual running container's name with `docker ps --format '{{.Names}}'` and use that exact name.

Example fix

# before
networkMode: container:my_db/v2
# after
networkMode: container:my_db-v2
Defensive patterns

Strategy: validation

Validate before calling

var containerNameRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`)
func validContainerName(name string) bool { return containerNameRe.MatchString(name) }

Type guard

if !validContainerName(strings.TrimPrefix(mode, "container:")) { /* invalid name */ }

Try / catch

if err != nil {
    var se *sErrors.Error
    if errors.As(err, &se) && se.ErrCode == proto.StatusCode_INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME {
        // fix the container name per suggestion and retry
    }
}

Prevention

When it happens

Trigger: networkMode container:<name> where <name> fails the Docker container-name regexp (e.g. starts with '.', '_', '-' or contains ':', '/', spaces).

Common situations: Copy-pasted container IDs or URIs, names with slashes/colons, or empty/whitespace names in skaffold.yaml.

Related errors


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