{"record":{"id":"ef532d5833cba960","repo":"jesseduffield/lazydocker","slug":"container-does-not-support-attaching-you-must-eit","errorCode":null,"errorMessage":"Container does not support attaching. You must either run the service with the '-it' flag or use `stdin_open: true, tty: true` in the docker-compose.yml file","messagePattern":"Container does not support attaching\\. You must either run the service with the '-it' flag or use `stdin_open: true, tty: true` in the docker-compose\\.yml file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/container.go","lineNumber":98,"sourceCode":"\tc.Log.Warn(fmt.Sprintf(\"unpausing container %s\", c.Name))\n\treturn c.Client.ContainerUnpause(context.Background(), c.ID)\n}\n\n// Restart restarts the container\nfunc (c *Container) Restart() error {\n\tc.Log.Warn(fmt.Sprintf(\"restarting container %s\", c.Name))\n\treturn c.Client.ContainerRestart(context.Background(), c.ID, container.StopOptions{})\n}\n\n// Attach attaches the container\nfunc (c *Container) Attach() (*exec.Cmd, error) {\n\tif !c.DetailsLoaded() {\n\t\treturn nil, errors.New(c.Tr.WaitingForContainerInfo)\n\t}\n\n\t// verify that we can in fact attach to this container\n\tif !c.Details.Config.OpenStdin {\n\t\treturn nil, errors.New(c.Tr.UnattachableContainerError)\n\t}\n\n\tif c.Container.State == \"exited\" {\n\t\treturn nil, errors.New(c.Tr.CannotAttachStoppedContainerError)\n\t}\n\n\tc.Log.Warn(fmt.Sprintf(\"attaching to container %s\", c.Name))\n\t// TODO: use SDK\n\tcmd := c.OSCommand.NewCmd(\"docker\", \"attach\", \"--sig-proxy=false\", c.ID)\n\treturn cmd, nil\n}\n\n// Top returns process information\nfunc (c *Container) Top(ctx context.Context) (container.TopResponse, error) {\n\tdetail, err := c.Inspect()\n\tif err != nil {\n\t\treturn container.TopResponse{}, err\n\t}","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/jesseduffield/lazydocker/blob/7e7aadc2071d58031bf2daafca1fbd4093efc23f/pkg/commands/container.go#L80-L116","documentation":"Thrown by Container.Attach() when the container's inspect payload shows Config.OpenStdin == false. 'docker attach' only makes sense for containers started with an interactive stdin, so lazydocker refuses to attach to containers created without -it (or stdin_open: true, tty: true in compose). The message itself tells you the two supported remedies.","triggerScenarios":"Calling Container.Attach() on a container created with `docker run` without -i/-t flags, or on a compose service whose yaml lacks `stdin_open: true` and `tty: true`, after details have loaded and OpenStdin is false.","commonSituations":"Background services (databases, web servers) defined in docker-compose.yml with no tty/stdin_open; containers started by CI or orchestration tools that never allocate stdin; long-running daemon containers where attach is the wrong tool and `docker exec -it ... sh` is what the user actually wants.","solutions":["Recreate the container with an interactive TTY: `docker run -it ...` or add `stdin_open: true` and `tty: true` to the service in docker-compose.yml.","If you only need a shell, use exec instead: `docker exec -it <container> sh` (in lazydocker this is the 'E' key), which does not require OpenStdin.","For compose services: `docker compose up -d --force-recreate <service>` after editing the yaml so the new flags take effect."],"exampleFix":"# before (docker-compose.yml)\nservices:\n  app:\n    image: myapp\n\n# after (docker-compose.yml)\nservices:\n  app:\n    image: myapp\n    stdin_open: true\n    tty: true","handlingStrategy":"validation","validationCode":"detail, err := container.Inspect()\nif err != nil {\n    return err\n}\nif !detail.Config.OpenStdin {\n    // show guidance instead of attempting attach\n    return showHint(\"recreate with -it or stdin_open+tty in compose\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := container.Attach(); err != nil {\n    if strings.Contains(err.Error(), \"-it\") { // UnattachableContainerError\n        suggestExecInstead(container)\n    }\n}","preventionTips":["Run interactive containers with `docker run -it` from the start.","Add `stdin_open: true` and `tty: true` to compose services you expect to attach to.","Prefer exec (`docker exec -it ... sh`) for shells in non-interactive containers — it never needs OpenStdin."],"tags":["docker","container-attach","configuration","tty"],"backgroundTag":null,"analyzedSha":"7e7aadc2071d58031bf2daafca1fbd4093efc23f","analyzedAt":"2026-08-15T09:51:48.093Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}