{"id":"6c0fa91aadd1571f","repo":"docker/cli","slug":"network-q-is-declared-as-external-but-could-not","errorCode":null,"errorMessage":"network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed","messagePattern":"network %q is declared as external, but could not be found\\. You need to create a swarm-scoped network before the stack is deployed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/stack/deploy_composefile.go","lineNumber":100,"sourceCode":"\t\t}\n\t\tfor nw := range serviceConfig.Networks {\n\t\t\tserviceNetworks[nw] = struct{}{}\n\t\t}\n\t}\n\treturn serviceNetworks\n}\n\nfunc validateExternalNetworks(ctx context.Context, apiClient client.NetworkAPIClient, externalNetworks []string) error {\n\tfor _, networkName := range externalNetworks {\n\t\tif !container.NetworkMode(networkName).IsUserDefined() {\n\t\t\t// Networks that are not user defined always exist on all nodes as\n\t\t\t// local-scoped networks, so there's no need to inspect them.\n\t\t\tcontinue\n\t\t}\n\t\tres, err := apiClient.NetworkInspect(ctx, networkName, client.NetworkInspectOptions{})\n\t\tswitch {\n\t\tcase errdefs.IsNotFound(err):\n\t\t\treturn fmt.Errorf(\"network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed\", networkName)\n\t\tcase err != nil:\n\t\t\treturn err\n\t\tcase res.Network.Scope != \"swarm\":\n\t\t\treturn fmt.Errorf(\"network %q is declared as external, but it is not in the right scope: %q instead of \\\"swarm\\\"\", networkName, res.Network.Scope)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc createSecrets(ctx context.Context, dockerCLI command.Cli, secrets []swarm.SecretSpec) error {\n\tapiClient := dockerCLI.Client()\n\n\tfor _, secretSpec := range secrets {\n\t\tres, err := apiClient.SecretInspect(ctx, secretSpec.Name, client.SecretInspectOptions{})\n\t\tswitch {\n\t\tcase err == nil:\n\t\t\t// secret already exists, then we update that\n\t\t\t_, err := apiClient.SecretUpdate(ctx, res.Secret.ID, client.SecretUpdateOptions{","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/stack/deploy_composefile.go#L82-L118","documentation":"Error \"network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed\" thrown in docker/cli.","triggerScenarios":"Thrown at cli/command/stack/deploy_composefile.go:100 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}