From eebe6382271b8dcbc35909b4e0b72c27456e5e6c Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Mon, 2 Oct 2017 18:52:14 -0300 Subject: [PATCH] Remove volume when deleting container --- docker/docker.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index 35b2086..8a6b1b1 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -45,7 +45,7 @@ type DockerApi interface { ContainerRename(old, new string) error CreateAttachConnection(name string) (net.Conn, error) CopyToContainer(containerName, destination, fileName string, content io.Reader) error - DeleteContainer(id string) error + DeleteContainer(name string) error CreateContainer(opts CreateContainerOpts) error GetContainerIPs(id string) (map[string]string, error) ExecAttach(instanceName string, command []string, out io.Writer) (int, error) @@ -223,8 +223,9 @@ func (d *docker) CopyToContainer(containerName, destination, fileName string, co return d.c.CopyToContainer(context.Background(), containerName, destination, r, types.CopyToContainerOptions{AllowOverwriteDirWithFile: true}) } -func (d *docker) DeleteContainer(id string) error { - return d.c.ContainerRemove(context.Background(), id, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}) +func (d *docker) DeleteContainer(name string) error { + d.c.VolumeRemove(context.Background(), name, true) + return d.c.ContainerRemove(context.Background(), name, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}) } type CreateContainerOpts struct { @@ -322,7 +323,7 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) (err error) { DriverOpts: map[string]string{ "size": config.DindVolumeSize, }, - Name: opts.SessionId, + Name: opts.ContainerName, }) if err != nil { return