{"record":{"id":"58c9687175ba0da1","repo":"docker/cli","slug":"error-this-node-is-not-part-of-a-swarm","errorCode":null,"errorMessage":"error: this node is not part of a swarm","messagePattern":"error: this node is not part of a swarm","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/swarm/unlock.go","lineNumber":51,"sourceCode":"\t\tDisableFlagsInUseLine: true,\n\t}\n\n\treturn cmd\n}\n\nfunc runUnlock(ctx context.Context, dockerCLI command.Cli) error {\n\tapiClient := dockerCLI.Client()\n\n\t// First see if the node is actually part of a swarm, and if it is actually locked first.\n\t// If it's in any other state than locked, don't ask for the key.\n\tres, err := apiClient.Info(ctx, client.InfoOptions{})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tswitch res.Info.Swarm.LocalNodeState {\n\tcase swarm.LocalNodeStateInactive:\n\t\treturn errors.New(\"error: this node is not part of a swarm\")\n\tcase swarm.LocalNodeStateLocked:\n\t\tbreak\n\tcase swarm.LocalNodeStatePending, swarm.LocalNodeStateActive, swarm.LocalNodeStateError:\n\t\treturn errors.New(\"error: swarm is not locked\")\n\t}\n\n\tkey, err := readKey(dockerCLI.In(), \"Enter unlock key: \")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = apiClient.SwarmUnlock(ctx, client.SwarmUnlockOptions{\n\t\tKey: key,\n\t})\n\treturn err\n}\n\nfunc readKey(in *streams.In, prompt string) (string, error) {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/swarm/unlock.go#L33-L69","documentation":"Thrown by runUnlock (cli/command/swarm/unlock.go:51) when an Info call reports LocalNodeState == Inactive, meaning this engine has never joined or initialized a swarm. There is nothing to unlock, so the command refuses rather than prompting for a key.","triggerScenarios":"Running `docker swarm unlock` on a node that was never part of a swarm, or that left the swarm (`docker swarm leave`) and is now inactive.","commonSituations":"Wrong host; fresh install; swarm was dissolved/left; node reset to factory state.","solutions":["Initialize or join a swarm first: `docker swarm init` (manager) or `docker swarm join --token <t> <ip:2377>`.","Confirm the node's swarm state with `docker info` (look for `Swarm: inactive`)."],"exampleFix":"// before (not in a swarm)\ndocker swarm unlock   # -> error: this node is not part of a swarm\n\n// after\ndocker swarm init   # or: docker swarm join --token <t> <ip:2377>","handlingStrategy":"validation","validationCode":"res, err := apiClient.Info(ctx, client.InfoOptions{})\nif err != nil { return err }\nif res.Info.Swarm.LocalNodeState == swarm.LocalNodeStateInactive {\n\treturn errors.New(\"node is not in a swarm; init or join first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check `docker info` swarm state before unlock operations.","Automate swarm init/join in provisioning so nodes are never inert.","Guard scripts against running on freshly-imaged nodes."],"tags":["docker","swarm","unlock","state"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}