mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
Filter containers by project name if provided
This commit is contained in:
parent
57d30172be
commit
e784853b9e
3 changed files with 17 additions and 7 deletions
|
|
@ -16,6 +16,7 @@ import (
|
||||||
ddocker "github.com/docker/cli/cli/context/docker"
|
ddocker "github.com/docker/cli/cli/context/docker"
|
||||||
ctxstore "github.com/docker/cli/cli/context/store"
|
ctxstore "github.com/docker/cli/cli/context/store"
|
||||||
dockerTypes "github.com/docker/docker/api/types"
|
dockerTypes "github.com/docker/docker/api/types"
|
||||||
|
dockerFilters "github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/commands/ssh"
|
"github.com/jesseduffield/lazydocker/pkg/commands/ssh"
|
||||||
|
|
@ -199,7 +200,11 @@ func (c *DockerCommand) GetContainers(existingContainers []*Container) ([]*Conta
|
||||||
c.ContainerMutex.Lock()
|
c.ContainerMutex.Lock()
|
||||||
defer c.ContainerMutex.Unlock()
|
defer c.ContainerMutex.Unlock()
|
||||||
|
|
||||||
containers, err := c.Client.ContainerList(context.Background(), dockerTypes.ContainerListOptions{All: true})
|
filters := dockerFilters.NewArgs()
|
||||||
|
if c.Config.ProjectName != "" {
|
||||||
|
filters.Add("label", "com.docker.compose.project="+c.Config.ProjectName)
|
||||||
|
}
|
||||||
|
containers, err := c.Client.ContainerList(context.Background(), dockerTypes.ContainerListOptions{All: true, Filters: filters})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -484,6 +484,7 @@ type AppConfig struct {
|
||||||
UserConfig *UserConfig
|
UserConfig *UserConfig
|
||||||
ConfigDir string
|
ConfigDir string
|
||||||
ProjectDir string
|
ProjectDir string
|
||||||
|
ProjectName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAppConfig makes a new app config
|
// NewAppConfig makes a new app config
|
||||||
|
|
@ -516,6 +517,7 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
|
||||||
UserConfig: userConfig,
|
UserConfig: userConfig,
|
||||||
ConfigDir: configDir,
|
ConfigDir: configDir,
|
||||||
ProjectDir: projectDir,
|
ProjectDir: projectDir,
|
||||||
|
ProjectName: projectName,
|
||||||
}
|
}
|
||||||
|
|
||||||
return appConfig, nil
|
return appConfig, nil
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,15 @@ func (gui *Gui) refreshProject() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) getProjectName() string {
|
func (gui *Gui) getProjectName() string {
|
||||||
projectName := path.Base(gui.Config.ProjectDir)
|
projectName := gui.Config.ProjectName
|
||||||
if gui.DockerCommand.InDockerComposeProject {
|
if projectName == "" {
|
||||||
for _, service := range gui.Panels.Services.List.GetAllItems() {
|
projectName = path.Base(gui.Config.ProjectDir)
|
||||||
container := service.Container
|
if gui.DockerCommand.InDockerComposeProject {
|
||||||
if container != nil && container.DetailsLoaded() {
|
for _, service := range gui.Panels.Services.List.GetAllItems() {
|
||||||
return container.Details.Config.Labels["com.docker.compose.project"]
|
container := service.Container
|
||||||
|
if container != nil && container.DetailsLoaded() {
|
||||||
|
return container.Details.Config.Labels["com.docker.compose.project"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue