diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 0ce4fba1..b055441a 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -154,9 +154,25 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat log.Warn(err.Error()) } + // When the user passes -p outside of a compose directory, treat it as the + // local project so the project/services panels still appear and filtering + // is applied. Inside a compose dir, LocalProjectName is derived from + // container labels later in RefreshContainersAndServices. + if !dockerCommand.InDockerComposeProject && config.ProjectName != "" { + dockerCommand.LocalProjectName = config.ProjectName + } + return dockerCommand, nil } +// IsProjectScoped reports whether lazydocker should be scoped to a single +// compose project — either because we're inside a compose directory or +// because the user passed -p. When false, the project/services panels are +// hidden and all containers are shown in a flat list. +func (c *DockerCommand) IsProjectScoped() bool { + return c.InDockerComposeProject || c.Config.ProjectName != "" +} + func (c *DockerCommand) setDockerComposeCommand(config *config.AppConfig) { if config.UserConfig.CommandTemplates.DockerCompose != "docker compose" { return diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 5410502d..f9254b94 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -87,11 +87,10 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container] return false } - // Only apply project and standalone filtering when we are inside a - // docker-compose project. Outside of a compose project all - // containers are shown in a flat list regardless of which compose - // project they belong to. - if gui.DockerCommand.InDockerComposeProject { + // When project-scoped, apply project and standalone filtering. + // Otherwise all containers are shown in a flat list regardless + // of which compose project they belong to. + if gui.DockerCommand.IsProjectScoped() { // This check must be inside the InDockerComposeProject guard: // outside a compose project, services are still derived from // container labels, so compose-managed containers from other diff --git a/pkg/gui/project_panel.go b/pkg/gui/project_panel.go index a7c6ef55..13e281ca 100644 --- a/pkg/gui/project_panel.go +++ b/pkg/gui/project_panel.go @@ -59,12 +59,7 @@ func (gui *Gui) getProjectPanel() *panels.SideListPanel[*commands.Project] { return gui.renderContainersAndServices() }, Hide: func() bool { - // Only show the project panel when we are inside a docker-compose - // project directory. When launched outside of a compose project - // there is no meaningful local project to display, so we hide the - // panel and let the containers panel show all containers in a flat - // list (matching the behaviour from before v0.25). - return !gui.DockerCommand.InDockerComposeProject + return !gui.DockerCommand.IsProjectScoped() }, } } @@ -195,6 +190,11 @@ func (gui *Gui) renderAllLogs(project *commands.Project) tasks.TaskFunc { } func (gui *Gui) renderDockerComposeConfig(project *commands.Project) tasks.TaskFunc { + if !gui.DockerCommand.InDockerComposeProject { + return gui.NewSimpleRenderStringTask(func() string { + return "Compose config is only available when launched from a docker-compose project directory" + }) + } if project != nil && project.Name != gui.DockerCommand.LocalProjectName { return gui.NewSimpleRenderStringTask(func() string { return "Compose config is not available for non-local projects" diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index 878eaa4b..edc894e9 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -90,12 +90,7 @@ func (gui *Gui) getServicesPanel() *panels.SideListPanel[*commands.Service] { return presentation.GetServiceDisplayStrings(&gui.Config.UserConfig.Gui, service) }, Hide: func() bool { - // Only show the services panel when we are inside a docker-compose - // project directory. When launched outside of a compose project - // there is no local project context, so the panel is hidden and - // all containers are shown in a flat list (matching pre-v0.25 - // behaviour). - return !gui.DockerCommand.InDockerComposeProject + return !gui.DockerCommand.IsProjectScoped() }, } }