From 4b42ba47b1c84b384154da0acde6f01554e04bbc Mon Sep 17 00:00:00 2001 From: Karim Radhouani Date: Tue, 27 Oct 2020 21:33:08 +0800 Subject: [PATCH] remove prefix "/" from container name --- clab/docker.go | 6 +++--- cmd/destroy.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clab/docker.go b/clab/docker.go index 255721bca..2ce4eae22 100644 --- a/clab/docker.go +++ b/clab/docker.go @@ -313,15 +313,15 @@ func (c *cLab) Exec(ctx context.Context, id string, cmd []string) ([]byte, []byt } // DeleteContainer tries to stop a container then remove it -func (c *cLab) DeleteContainer(ctx context.Context, name string, cid string, timeout time.Duration) error { +func (c *cLab) DeleteContainer(ctx context.Context, name string, timeout time.Duration) error { force := false - err := c.DockerClient.ContainerStop(ctx, cid, &timeout) + err := c.DockerClient.ContainerStop(ctx, name, &timeout) if err != nil { log.Errorf("could not stop container '%s': %v", name, err) force = true } log.Infof("Removing container: %s", name) - err = c.DockerClient.ContainerRemove(ctx, cid, types.ContainerRemoveOptions{Force: force}) + err = c.DockerClient.ContainerRemove(ctx, name, types.ContainerRemoveOptions{Force: force}) if err != nil { return err } diff --git a/cmd/destroy.go b/cmd/destroy.go index 4557a47bd..d73a429c6 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -51,10 +51,10 @@ var destroyCmd = &cobra.Command{ defer wg.Done() name := cont.ID if len(cont.Names) > 0 { - name = cont.Names[0] + name = strings.TrimLeft(cont.Names[0], "/") } log.Infof("Stopping container: %s", name) - err = c.DeleteContainer(ctx, name, cont.ID, 30*time.Second) + err = c.DeleteContainer(ctx, name, 30*time.Second) if err != nil { log.Errorf("could not remove container '%s': %v", name, err) }