{"record":{"id":"2413fd6ad9aaa05d","repo":"docker/cli","slug":"error-swarm-is-not-locked","errorCode":null,"errorMessage":"error: swarm is not locked","messagePattern":"error: swarm is not locked","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/command/swarm/unlock.go","lineNumber":55,"sourceCode":"}\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) {\n\tif in.IsTerminal() {\n\t\tfmt.Print(prompt)\n\t\tdt, err := term.ReadPassword(int(in.FD()))\n\t\tfmt.Println()","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/swarm/unlock.go#L37-L73","documentation":"Thrown by runUnlock (cli/command/swarm/unlock.go:55) when LocalNodeState is Pending, Active, or Error — i.e. the swarm is reachable without an unlock key. Only the Locked state requires unlocking; any other live state means the operation is unnecessary, so the command refuses to prompt for a key.","triggerScenarios":"Running `docker swarm unlock` when the manager is already active (autolock off, or already unlocked), in Pending (mid-operation), or in Error state.","commonSituations":"Operator runs unlock out of habit on an already-running swarm; autolock is disabled so the manager never locks; the node is mid-convergence.","solutions":["No action needed — the swarm is already accessible.","If you expected a locked state, verify autolock is enabled: `docker swarm unlock-key` (it will tell you if autolock is off).","For an Error state, inspect `docker info` and address the underlying swarm problem first."],"exampleFix":"// before\ndocker swarm unlock   # swarm already active -> error: swarm is not locked\n\n// after\n# nothing to do; optionally confirm autolock status\ndocker swarm unlock-key","handlingStrategy":"validation","validationCode":"res, err := apiClient.Info(ctx, client.InfoOptions{})\nif err != nil { return err }\nif res.Info.Swarm.LocalNodeState != swarm.LocalNodeStateLocked {\n\t// nothing to unlock; treat as a no-op rather than an error.\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call unlock when LocalNodeState is Locked.","If autolock is off, expect the swarm to never lock — don't script unlock.","Surface a friendly 'already unlocked' message instead of failing."],"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"}