1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Make error message consistent when removing containers fail.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2016-02-01 15:30:58 -05:00
parent 69c381c8d1
commit 50de9fdff1
2 changed files with 21 additions and 19 deletions

View file

@ -28,15 +28,8 @@ func (cli *DockerCli) CmdRm(args ...string) error {
} }
name = strings.Trim(name, "/") name = strings.Trim(name, "/")
options := types.ContainerRemoveOptions{ if err := cli.removeContainer(name, *v, *link, *force); err != nil {
ContainerID: name, errs = append(errs, err.Error())
RemoveVolumes: *v,
RemoveLinks: *link,
Force: *force,
}
if err := cli.client.ContainerRemove(options); err != nil {
errs = append(errs, fmt.Sprintf("Failed to remove container (%s): %s", name, err))
} else { } else {
fmt.Fprintf(cli.out, "%s\n", name) fmt.Fprintf(cli.out, "%s\n", name)
} }
@ -46,3 +39,16 @@ func (cli *DockerCli) CmdRm(args ...string) error {
} }
return nil return nil
} }
func (cli *DockerCli) removeContainer(containerID string, removeVolumes, removeLinks, force bool) error {
options := types.ContainerRemoveOptions{
ContainerID: containerID,
RemoveVolumes: removeVolumes,
RemoveLinks: removeLinks,
Force: force,
}
if err := cli.client.ContainerRemove(options); err != nil {
return fmt.Errorf("Failed to remove container (%s): %v", containerID, err)
}
return nil
}

View file

@ -218,17 +218,13 @@ func (cli *DockerCli) CmdRun(args ...string) error {
}) })
} }
defer func() { if *flAutoRemove {
if *flAutoRemove { defer func() {
options := types.ContainerRemoveOptions{ if err := cli.removeContainer(createResponse.ID, true, false, false); err != nil {
ContainerID: createResponse.ID, fmt.Fprintf(cli.err, "%v\n", err)
RemoveVolumes: true,
} }
if err := cli.client.ContainerRemove(options); err != nil { }()
fmt.Fprintf(cli.err, "Error deleting container: %s\n", err) }
}
}
}()
//start the container //start the container
if err := cli.client.ContainerStart(createResponse.ID); err != nil { if err := cli.client.ContainerStart(createResponse.ID); err != nil {