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"
|
||||
ctxstore "github.com/docker/cli/cli/context/store"
|
||||
dockerTypes "github.com/docker/docker/api/types"
|
||||
dockerFilters "github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/jesseduffield/lazydocker/pkg/commands/ssh"
|
||||
|
|
@ -199,7 +200,11 @@ func (c *DockerCommand) GetContainers(existingContainers []*Container) ([]*Conta
|
|||
c.ContainerMutex.Lock()
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -484,6 +484,7 @@ type AppConfig struct {
|
|||
UserConfig *UserConfig
|
||||
ConfigDir string
|
||||
ProjectDir string
|
||||
ProjectName string
|
||||
}
|
||||
|
||||
// NewAppConfig makes a new app config
|
||||
|
|
@ -516,6 +517,7 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
|
|||
UserConfig: userConfig,
|
||||
ConfigDir: configDir,
|
||||
ProjectDir: projectDir,
|
||||
ProjectName: projectName,
|
||||
}
|
||||
|
||||
return appConfig, nil
|
||||
|
|
|
|||
|
|
@ -78,12 +78,15 @@ func (gui *Gui) refreshProject() error {
|
|||
}
|
||||
|
||||
func (gui *Gui) getProjectName() string {
|
||||
projectName := path.Base(gui.Config.ProjectDir)
|
||||
if gui.DockerCommand.InDockerComposeProject {
|
||||
for _, service := range gui.Panels.Services.List.GetAllItems() {
|
||||
container := service.Container
|
||||
if container != nil && container.DetailsLoaded() {
|
||||
return container.Details.Config.Labels["com.docker.compose.project"]
|
||||
projectName := gui.Config.ProjectName
|
||||
if projectName == "" {
|
||||
projectName = path.Base(gui.Config.ProjectDir)
|
||||
if gui.DockerCommand.InDockerComposeProject {
|
||||
for _, service := range gui.Panels.Services.List.GetAllItems() {
|
||||
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