{"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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/swarm/unlock.go#L33-L69","documentation":"Returned by `docker swarm unlock` when the daemon's Info reports LocalNodeState == inactive, meaning this node has never joined (or has left) a swarm. The CLI checks node state before prompting for an unlock key, so it fails fast instead of asking for a key that can't be used.","triggerScenarios":"Running `docker swarm unlock` on a host where `Info.Swarm.LocalNodeState` is `inactive` — the node is not part of any swarm. Only the Info API call is made; SwarmUnlock is never attempted.","commonSituations":"Running unlock on the wrong host (a worker that left, or a fresh machine); DOCKER_HOST/context pointing at a non-swarm daemon; the node was removed from the swarm or `docker swarm leave` was run; confusion after a daemon reinstall wiped swarm state.","solutions":["Check where your CLI points (`docker context show`, `DOCKER_HOST`) and run the command on an actual swarm manager.","Verify node state with `docker info --format '{{.Swarm.LocalNodeState}}'`.","If the node should be in the swarm, rejoin it with `docker swarm join` (unlock only applies to already-joined locked managers).","If you meant to create a swarm, run `docker swarm init` instead."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker","swarm","autolock","node-state"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}