{"record":{"id":"1acea5fd1b1261f9","repo":"docker/cli","slug":"failed-to-create-config-s-w","errorCode":null,"errorMessage":"failed to create config %s: %w","messagePattern":"failed to create config (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/stack/deploy_composefile.go","lineNumber":163,"sourceCode":"\t\tres, err := apiClient.ConfigInspect(ctx, configSpec.Name, client.ConfigInspectOptions{})\n\t\tswitch {\n\t\tcase err == nil:\n\t\t\t// config already exists, then we update that\n\t\t\t_, err := apiClient.ConfigUpdate(ctx, res.Config.ID, client.ConfigUpdateOptions{\n\t\t\t\tVersion: res.Config.Meta.Version,\n\t\t\t\tSpec:    configSpec,\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to update config %s: %w\", configSpec.Name, err)\n\t\t\t}\n\t\tcase errdefs.IsNotFound(err):\n\t\t\t// config does not exist, then we create a new one.\n\t\t\t_, _ = fmt.Fprintln(dockerCLI.Out(), \"Creating config\", configSpec.Name)\n\t\t\t_, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{\n\t\t\t\tSpec: configSpec,\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create config %s: %w\", configSpec.Name, err)\n\t\t\t}\n\t\tdefault:\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc createNetworks(ctx context.Context, dockerCLI command.Cli, namespace convert.Namespace, networks map[string]client.NetworkCreateOptions) error {\n\tapiClient := dockerCLI.Client()\n\n\texistingNetworks, err := getStackNetworks(ctx, apiClient, namespace.Name())\n\tif err != nil {\n\t\treturn err\n\t}\n\n\texistingNetworkMap := make(map[string]network.Summary)\n\tfor _, nw := range existingNetworks.Items {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/stack/deploy_composefile.go#L145-L181","documentation":"Raised by createConfigs when a config does not exist yet (NotFound after ConfigInspect) and the ConfigCreate API call then fails. The wrapped %w carries the underlying daemon error (invalid name, oversized data, driver error).","triggerScenarios":"First-time deploy of a stack with configs defined in compose.yml, where ConfigCreate at deploy_composefile.go:159 fails. Also when a config is removed between Inspect and Create, producing a name collision.","commonSituations":"Config data exceeding the 500KB limit; invalid config name; concurrent deploy creating the same config; external config driver issues.","solutions":["Inspect the wrapped error for the daemon's reason.","Ensure config names are valid ([a-zA-Z0-9_.-], <= 64 chars, lowercase recommended) and data <= 500KB.","Retry the deploy; concurrent races resolve as an update next time.","Verify the config file referenced in compose.yml exists and is readable."],"exampleFix":"// before: referenced config file missing / too large\nconfigs:\n  big:\n    file: ./large.bin   # > 500KB\n// after: keep config data under 500KB\nconfigs:\n  big:\n    file: ./small.txt","handlingStrategy":"validation","validationCode":"// Validate config names and sizes before deploy\nconst maxConfigBytes = 500 * 1024\nvar validName = regexp.MustCompile(`^[a-zA-Z0-9](?:[a-zA-Z0-9_.-]{0,63})$`)\n\nfunc validateConfig(name string, data []byte, stackNS string) error {\n    full := stackNS + \"_\" + name\n    if !validName.MatchString(full) || len(full) > 64 {\n        return fmt.Errorf(\"invalid config name %q\", full)\n    }\n    if len(data) > maxConfigBytes {\n        return fmt.Errorf(\"config %q too large: %d bytes\", name, len(data))\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep config data under 500KB.","Use valid lowercase names.","Ensure referenced config files exist and are readable in CI."],"tags":["docker","stack","config","swarm","create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}