{"record":{"id":"f131fd01abb77386","repo":"jesseduffield/lazydocker","slug":"container-is-not-running","errorCode":null,"errorMessage":"container is not running","messagePattern":"container is not running","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/container.go","lineNumber":120,"sourceCode":"\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}\n\n\t// check container status\n\tif !detail.State.Running {\n\t\treturn container.TopResponse{}, errors.New(\"container is not running\")\n\t}\n\n\treturn c.Client.ContainerTop(ctx, c.ID, []string{})\n}\n\n// PruneContainers prunes containers\nfunc (c *DockerCommand) PruneContainers() error {\n\t_, err := c.Client.ContainersPrune(context.Background(), filters.Args{})\n\treturn err\n}\n\n// Inspect returns details about the container\nfunc (c *Container) Inspect() (container.InspectResponse, error) {\n\treturn c.Client.ContainerInspect(context.Background(), c.ID)\n}\n\n// RenderTop returns details about the container\nfunc (c *Container) RenderTop(ctx context.Context) (string, error) {","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/jesseduffield/lazydocker/blob/7e7aadc2071d58031bf2daafca1fbd4093efc23f/pkg/commands/container.go#L102-L138","documentation":"Thrown by Container.Top() after a successful Inspect() reveals detail.State.Running == false. The Docker API's ContainerTop endpoint (which this function calls next) only works on running containers, so lazydocker pre-checks the state and returns this error instead of a raw API 409/500 error from the daemon.","triggerScenarios":"Calling Container.Top(ctx) on a container whose inspected State.Running is false — stopped, exited, paused-and-stopped, or created-but-never-started containers. Also hit when the container stops between the UI listing it and the user opening the top/stats tab.","commonSituations":"Opening the process/stats view on a stopped container that is still visible in the side list; a container that exits while the user is navigating to its stats tab; scripting against lazydocker's Container.Top without checking lifecycle state first.","solutions":["Start the container ('r' key or `docker start <id>`) and retry Top once State.Running is true.","Guard the call: check the container's State via Inspect or the cached state string before invoking Top.","If the container should not keep exiting, inspect `docker logs` for the root crash cause."],"exampleFix":"// before\n top, err := container.Top(ctx)\nif err != nil {\n    return err\n}\n\n// after\n detail, err := container.Inspect()\nif err != nil {\n    return err\n}\nif !detail.State.Running {\n    return fmt.Errorf(\"container %s is not running\", container.Name)\n}\ntop, err := container.Top(ctx)","handlingStrategy":"validation","validationCode":"detail, err := container.Inspect()\nif err != nil {\n    return err\n}\nif !detail.State.Running {\n    return nil // skip stats/top view for non-running containers\n}","typeGuard":null,"tryCatchPattern":"top, err := container.Top(ctx)\nif err != nil && err.Error() == \"container is not running\" {\n    // render an empty stats view instead of an error popup\n    return renderEmptyStats(container)\n}","preventionTips":["Gate stats/top views on State.Running before invoking Top().","Re-check state at render time, not at list-load time — containers can stop in between.","Handle stopped containers gracefully in the UI rather than treating them as an error path."],"tags":["docker","container-top","container-lifecycle","validation"],"backgroundTag":null,"analyzedSha":"7e7aadc2071d58031bf2daafca1fbd4093efc23f","analyzedAt":"2026-08-15T09:51:48.093Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}