jesseduffield/lazydocker · error
container is not running
Error message
container is not running
What it means
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.
Source
Thrown at pkg/commands/container.go:120
return nil, errors.New(c.Tr.CannotAttachStoppedContainerError)
}
c.Log.Warn(fmt.Sprintf("attaching to container %s", c.Name))
// TODO: use SDK
cmd := c.OSCommand.NewCmd("docker", "attach", "--sig-proxy=false", c.ID)
return cmd, nil
}
// Top returns process information
func (c *Container) Top(ctx context.Context) (container.TopResponse, error) {
detail, err := c.Inspect()
if err != nil {
return container.TopResponse{}, err
}
// check container status
if !detail.State.Running {
return container.TopResponse{}, errors.New("container is not running")
}
return c.Client.ContainerTop(ctx, c.ID, []string{})
}
// PruneContainers prunes containers
func (c *DockerCommand) PruneContainers() error {
_, err := c.Client.ContainersPrune(context.Background(), filters.Args{})
return err
}
// Inspect returns details about the container
func (c *Container) Inspect() (container.InspectResponse, error) {
return c.Client.ContainerInspect(context.Background(), c.ID)
}
// RenderTop returns details about the container
func (c *Container) RenderTop(ctx context.Context) (string, error) {View on GitHub (pinned to 7e7aadc207)
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.
Example fix
// before
top, err := container.Top(ctx)
if err != nil {
return err
}
// after
detail, err := container.Inspect()
if err != nil {
return err
}
if !detail.State.Running {
return fmt.Errorf("container %s is not running", container.Name)
}
top, err := container.Top(ctx) Defensive patterns
Strategy: validation
Validate before calling
detail, err := container.Inspect()
if err != nil {
return err
}
if !detail.State.Running {
return nil // skip stats/top view for non-running containers
} Try / catch
top, err := container.Top(ctx)
if err != nil && err.Error() == "container is not running" {
// render an empty stats view instead of an error popup
return renderEmptyStats(container)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- You cannot attach to a stopped container, you need to start
- Cannot proceed until docker gives us more information about
- Container does not support attaching. You must either run th
- {stderr}
- {joined stderr}
AI-assisted analysis of jesseduffield/lazydocker@7e7aadc207 (2026-08-15).
Data as JSON: /api/errors/f131fd01abb77386.
Report an issue: GitHub.