diff --git a/internal/resource/container.go b/internal/resource/container.go index 8ada971..c57355e 100644 --- a/internal/resource/container.go +++ b/internal/resource/container.go @@ -12,7 +12,7 @@ _ "os" _ "gopkg.in/yaml.v3" _ "os/exec" _ "strings" - "log" + "log/slog" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/container" @@ -199,13 +199,14 @@ func (c *Container) Read(ctx context.Context) ([]byte, error) { All: true, Filters: filterArgs, }) + if err != nil { panic(fmt.Errorf("%w: %s %s", err, c.Type(), c.Name)) } for _, container := range containers { for _, containerName := range container.Names { - if containerName == c.Name { + if containerName == "/" + c.Name { containerID = container.ID } } @@ -217,7 +218,9 @@ func (c *Container) Read(ctx context.Context) ([]byte, error) { } else { c.State = "present" c.Id = containerJSON.ID - c.Name = containerJSON.Name + if c.Name == "" { + c.Name = containerJSON.Name + } c.Path = containerJSON.Path c.Image = containerJSON.Image if containerJSON.State != nil { @@ -231,6 +234,7 @@ func (c *Container) Read(ctx context.Context) ([]byte, error) { c.RestartCount = containerJSON.RestartCount c.Driver = containerJSON.Driver } + slog.Info("Read() ", "type", c.Type(), "name", c.Name, "Id", c.Id) return yaml.Marshal(c) } @@ -241,7 +245,7 @@ func (c *Container) Delete(ctx context.Context) error { Force: false, }) if err != nil { - log.Printf("Failed to remove: %s\n", c.Id) + slog.Error("Failed to remove: ", "Id", c.Id) panic(err) } return err