{"record":{"id":"9206ab957ebf934b","repo":"docker/cli","slug":"cannot-attach-to-a-paused-container-unpause-it-fi","errorCode":null,"errorMessage":"cannot attach to a paused container, unpause it first","messagePattern":"cannot attach to a paused container, unpause it first","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/attach.go","lineNumber":34,"sourceCode":")\n\n// AttachOptions group options for `attach` command\ntype AttachOptions struct {\n\tNoStdin    bool\n\tProxy      bool\n\tDetachKeys string\n}\n\nfunc inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*container.InspectResponse, error) {\n\tc, err := apiClient.ContainerInspect(ctx, args, client.ContainerInspectOptions{})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !c.Container.State.Running {\n\t\treturn nil, errors.New(\"cannot attach to a stopped container, start it first\")\n\t}\n\tif c.Container.State.Paused {\n\t\treturn nil, errors.New(\"cannot attach to a paused container, unpause it first\")\n\t}\n\tif c.Container.State.Restarting {\n\t\treturn nil, errors.New(\"cannot attach to a restarting container, wait until it is running\")\n\t}\n\n\treturn &c.Container, nil\n}\n\n// newAttachCommand creates a new cobra.Command for `docker attach`\nfunc newAttachCommand(dockerCLI command.Cli) *cobra.Command {\n\tvar opts AttachOptions\n\n\tcmd := &cobra.Command{\n\t\tUse:   \"attach [OPTIONS] CONTAINER\",\n\t\tShort: \"Attach local standard input, output, and error streams to a running container\",\n\t\tArgs:  cli.ExactArgs(1),\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tcontainerID := args[0]","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/attach.go#L16-L52","documentation":"inspectContainerAndCheckState returns errors.New(\"cannot attach to a paused container, unpause it first\") at line 34 when c.Container.State.Paused is true. A paused container has its processes frozen (cgroup freezer), so its I/O streams are not advancing and attach would hang; the CLI requires the container to be unpaused (Running and not Paused) first.","triggerScenarios":"Running `docker attach <id>` against a container previously paused via `docker pause <id>`, while it remains in the 'Paused' state.","commonSituations":"Pausing a container for debugging/snapshot then forgetting to unpause; automation that pauses before attach; pausing to inspect a memory dump.","solutions":["Unpause first: `docker unpause <id>` then `docker attach <id>`.","Confirm state with `docker ps`/`docker inspect` and look for Status 'Up (Paused)'.","Avoid pausing containers you intend to interact with via attach."],"exampleFix":"# before (container is paused)\ndocker attach web\n# after\ndocker unpause web && docker attach web","handlingStrategy":"validation","validationCode":"c, err := cli.Client().ContainerInspect(ctx, id, client.ContainerInspectOptions{})\nif err != nil { return err }\nif c.State.Paused {\n    // unpause before attach\n    _ = cli.Client().ContainerUnpause(ctx, id, client.ContainerUnpauseOptions{})\n}","typeGuard":null,"tryCatchPattern":"if _, err := inspectContainerAndCheckState(ctx, cli.Client(), id); err != nil {\n    if strings.Contains(err.Error(), \"paused container\") {\n        _ = cli.Client().ContainerUnpause(ctx, id, client.ContainerUnpauseOptions{})\n        // retry attach\n    }\n    return err\n}","preventionTips":["Avoid `docker pause` on containers you intend to attach to.","Check for 'Up (Paused)' status in `docker ps`.","Always unpause before interactive operations."],"tags":["container","attach","pause","lifecycle","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}