{"record":{"id":"6d0984d0fdd04165","repo":"GoogleContainerTools/skaffold","slug":"init-docker-network-invalid-container-name","errorCode":"INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME","errorMessage":"artifact %s has invalid container name '%s'","messagePattern":"artifact (.+?) has invalid container name '(.+?)'","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/schema/validation/validation.go","lineNumber":357,"sourceCode":"\t\t\t},\n\t\t})\n}\n\n// validateDockerNetworkModeExpression makes sure that the network mode starts with \"container:\" followed by a valid container name\nfunc validateDockerNetworkModeExpression(image string, expr string) error {\n\tid, err := extractContainerNameFromNetworkMode(expr)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn validateDockerContainerExpression(image, id)\n}\n\n// validateDockerContainerExpression makes sure that the container name pass in matches Docker's regular expression for containers\nfunc validateDockerContainerExpression(image string, id string) error {\n\tcontainerRegExp := regexp.MustCompile(\"^[a-zA-Z0-9][a-zA-Z0-9_.-]*$\")\n\tif !containerRegExp.MatchString(id) {\n\t\terrMsg := fmt.Sprintf(\"artifact %s has invalid container name '%s'\", image, id)\n\t\treturn sErrors.NewError(errors.New(errMsg),\n\t\t\t&proto.ActionableErr{\n\t\t\t\tMessage: errMsg,\n\t\t\t\tErrCode: proto.StatusCode_INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME,\n\t\t\t\tSuggestions: []*proto.Suggestion{\n\t\t\t\t\t{\n\t\t\t\t\t\tSuggestionCode: proto.SuggestionCode_FIX_DOCKER_NETWORK_CONTAINER_NAME,\n\t\t\t\t\t\tAction:         \"Please fix the docker network container name and try again\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t}\n\treturn nil\n}\n\n// validateDockerNetworkMode makes sure that networkMode is one of `bridge`, `none`, `container:<name|id>`, or `host` if set.\nfunc validateDockerNetworkMode(cfg *parser.SkaffoldConfigEntry, artifacts []*latest.Artifact) (cfgErrs []ErrorWithLocation) {\n\tfor i, a := range artifacts {\n\t\tif a.DockerArtifact == nil || a.DockerArtifact.NetworkMode == \"\" {","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/schema/validation/validation.go#L339-L375","documentation":"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.","triggerScenarios":"networkMode container:<name> where <name> fails the Docker container-name regexp (e.g. starts with '.', '_', '-' or contains ':', '/', spaces).","commonSituations":"Copy-pasted container IDs or URIs, names with slashes/colons, or empty/whitespace names in skaffold.yaml.","solutions":["Rename the referenced container (or the reference in skaffold.yaml) to a Docker-legal name: start with a letter/digit, then letters, digits, '_', '.', '-'.","Follow the actionable suggestion FIX_DOCKER_NETWORK_CONTAINER_NAME shown with the error.","Verify the actual running container's name with `docker ps --format '{{.Names}}'` and use that exact name."],"exampleFix":"# before\nnetworkMode: container:my_db/v2\n# after\nnetworkMode: container:my_db-v2","handlingStrategy":"validation","validationCode":"var containerNameRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`)\nfunc validContainerName(name string) bool { return containerNameRe.MatchString(name) }","typeGuard":"if !validContainerName(strings.TrimPrefix(mode, \"container:\")) { /* invalid name */ }","tryCatchPattern":"if err != nil {\n    var se *sErrors.Error\n    if errors.As(err, &se) && se.ErrCode == proto.StatusCode_INIT_DOCKER_NETWORK_INVALID_CONTAINER_NAME {\n        // fix the container name per suggestion and retry\n    }\n}","preventionTips":["Start container names with a letter or digit","Only use [a-zA-Z0-9_.-] after the first character","Copy exact names from `docker ps` output, not IDs or URIs"],"tags":["docker","network-mode","container-name","validation"],"backgroundTag":"invalid-docker-network-mode","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}