Fix panic: validate Names slice length and use containerID as container name if Names slice is empty in container summary

This commit is contained in:
ManManavadaria 2025-11-27 19:54:53 +05:30
parent 78edbf3d2e
commit 43db69da00

View file

@ -256,7 +256,11 @@ func (c *DockerCommand) GetContainers(existingContainers []*Container) ([]*Conta
if name, ok := ctr.Labels["name"]; ok {
newContainer.Name = name
} else {
newContainer.Name = strings.TrimLeft(ctr.Names[0], "/")
if len(ctr.Names) > 0 {
newContainer.Name = strings.TrimLeft(ctr.Names[0], "/")
} else {
newContainer.Name = ctr.ID
}
}
newContainer.ServiceName = ctr.Labels["com.docker.compose.service"]
newContainer.ProjectName = ctr.Labels["com.docker.compose.project"]