diff --git a/builder/internals.go b/builder/internals.go index b264918c3a..9e58bb251f 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -764,16 +764,14 @@ func fixPermissions(source, destination string, uid, gid int, destExisted bool) func (b *Builder) clearTmp() { for c := range b.TmpContainers { - tmp, err := b.Daemon.Get(c) - if err != nil { - fmt.Fprint(b.OutStream, err.Error()) + rmConfig := &daemon.ContainerRmConfig{ + ForceRemove: true, + RemoveVolume: true, } - - if err := b.Daemon.Rm(tmp); err != nil { + if err := b.Daemon.ContainerRm(c, rmConfig); err != nil { fmt.Fprintf(b.OutStream, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err) return } - b.Daemon.DeleteVolumes(tmp) delete(b.TmpContainers, c) fmt.Fprintf(b.OutStream, "Removing intermediate container %s\n", stringid.TruncateID(c)) } diff --git a/daemon/delete.go b/daemon/delete.go index b323f1b1db..830bbbe267 100644 --- a/daemon/delete.go +++ b/daemon/delete.go @@ -22,8 +22,6 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error name, err := GetFullContainerName(name) if err != nil { return err - // TODO: why was just job.Error(err) without return if the function cannot continue w/o container name? - //job.Error(err) } parent, n := path.Split(name) if parent == "/" { @@ -46,50 +44,31 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error return nil } - if container != nil { - // stop collection of stats for the container regardless - // if stats are currently getting collected. - daemon.statsCollector.stopCollection(container) - if container.IsRunning() { - if config.ForceRemove { - if err := container.Kill(); err != nil { - return fmt.Errorf("Could not kill running container, cannot remove - %v", err) - } - } else { - return fmt.Errorf("Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f") - } - } + if err := daemon.rm(container, config.ForceRemove); err != nil { + return fmt.Errorf("Cannot destroy container %s: %v", name, err) + } - if config.ForceRemove { - if err := daemon.ForceRm(container); err != nil { - logrus.Errorf("Cannot destroy container %s: %v", name, err) - } - } else { - if err := daemon.Rm(container); err != nil { - return fmt.Errorf("Cannot destroy container %s: %v", name, err) - } - } - container.LogEvent("destroy") + container.LogEvent("destroy") - if config.RemoveVolume { - container.removeMountPoints() - } + if config.RemoveVolume { + container.removeMountPoints() } return nil } -func (daemon *Daemon) Rm(container *Container) (err error) { - return daemon.commonRm(container, false) -} - -func (daemon *Daemon) ForceRm(container *Container) (err error) { - return daemon.commonRm(container, true) -} - // Destroy unregisters a container from the daemon and cleanly removes its contents from the filesystem. -func (daemon *Daemon) commonRm(container *Container, forceRemove bool) (err error) { - if container == nil { - return fmt.Errorf("The given container is ") +func (daemon *Daemon) rm(container *Container, forceRemove bool) (err error) { + // stop collection of stats for the container regardless + // if stats are currently getting collected. + daemon.statsCollector.stopCollection(container) + + if container.IsRunning() { + if !forceRemove { + return fmt.Errorf("Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f") + } + if err := container.Kill(); err != nil { + return fmt.Errorf("Could not kill running container, cannot remove - %v", err) + } } element := daemon.containers.Get(container.ID) diff --git a/integration-cli/docker_cli_cp_test.go b/integration-cli/docker_cli_cp_test.go index 26e778e4f2..d79615f241 100644 --- a/integration-cli/docker_cli_cp_test.go +++ b/integration-cli/docker_cli_cp_test.go @@ -435,7 +435,6 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) { } cleanedContainerID := strings.TrimSpace(out) - defer dockerCmd(c, "rm", "-fv", cleanedContainerID) out, _ = dockerCmd(c, "wait", cleanedContainerID) if strings.TrimSpace(out) != "0" {