Merge pull request #19896 from calavera/same_rm_error_message

Make error message consistent when removing containers fail.
This commit is contained in:
Brian Goff 2016-02-01 21:19:42 -05:00
Родитель f1e8d2c295 50de9fdff1
Коммит 3c0c115ec8
2 изменённых файлов: 21 добавлений и 19 удалений

Просмотреть файл

@ -28,15 +28,8 @@ func (cli *DockerCli) CmdRm(args ...string) error {
}
name = strings.Trim(name, "/")
options := types.ContainerRemoveOptions{
ContainerID: name,
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))
if err := cli.removeContainer(name, *v, *link, *force); err != nil {
errs = append(errs, err.Error())
} else {
fmt.Fprintf(cli.out, "%s\n", name)
}
@ -46,3 +39,16 @@ func (cli *DockerCli) CmdRm(args ...string) error {
}
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
}

Просмотреть файл

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