Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -28,15 +28,8 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
| 28 | 28 |
} |
| 29 | 29 |
name = strings.Trim(name, "/") |
| 30 | 30 |
|
| 31 |
- options := types.ContainerRemoveOptions{
|
|
| 32 |
- ContainerID: name, |
|
| 33 |
- RemoveVolumes: *v, |
|
| 34 |
- RemoveLinks: *link, |
|
| 35 |
- Force: *force, |
|
| 36 |
- } |
|
| 37 |
- |
|
| 38 |
- if err := cli.client.ContainerRemove(options); err != nil {
|
|
| 39 |
- errs = append(errs, fmt.Sprintf("Failed to remove container (%s): %s", name, err))
|
|
| 31 |
+ if err := cli.removeContainer(name, *v, *link, *force); err != nil {
|
|
| 32 |
+ errs = append(errs, err.Error()) |
|
| 40 | 33 |
} else {
|
| 41 | 34 |
fmt.Fprintf(cli.out, "%s\n", name) |
| 42 | 35 |
} |
| ... | ... |
@@ -46,3 +39,16 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
| 46 | 46 |
} |
| 47 | 47 |
return nil |
| 48 | 48 |
} |
| 49 |
+ |
|
| 50 |
+func (cli *DockerCli) removeContainer(containerID string, removeVolumes, removeLinks, force bool) error {
|
|
| 51 |
+ options := types.ContainerRemoveOptions{
|
|
| 52 |
+ ContainerID: containerID, |
|
| 53 |
+ RemoveVolumes: removeVolumes, |
|
| 54 |
+ RemoveLinks: removeLinks, |
|
| 55 |
+ Force: force, |
|
| 56 |
+ } |
|
| 57 |
+ if err := cli.client.ContainerRemove(options); err != nil {
|
|
| 58 |
+ return fmt.Errorf("Failed to remove container (%s): %v", containerID, err)
|
|
| 59 |
+ } |
|
| 60 |
+ return nil |
|
| 61 |
+} |
| ... | ... |
@@ -218,17 +218,13 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
| 218 | 218 |
}) |
| 219 | 219 |
} |
| 220 | 220 |
|
| 221 |
- defer func() {
|
|
| 222 |
- if *flAutoRemove {
|
|
| 223 |
- options := types.ContainerRemoveOptions{
|
|
| 224 |
- ContainerID: createResponse.ID, |
|
| 225 |
- RemoveVolumes: true, |
|
| 226 |
- } |
|
| 227 |
- if err := cli.client.ContainerRemove(options); err != nil {
|
|
| 228 |
- fmt.Fprintf(cli.err, "Error deleting container: %s\n", err) |
|
| 221 |
+ if *flAutoRemove {
|
|
| 222 |
+ defer func() {
|
|
| 223 |
+ if err := cli.removeContainer(createResponse.ID, true, false, false); err != nil {
|
|
| 224 |
+ fmt.Fprintf(cli.err, "%v\n", err) |
|
| 229 | 225 |
} |
| 230 |
- } |
|
| 231 |
- }() |
|
| 226 |
+ }() |
|
| 227 |
+ } |
|
| 232 | 228 |
|
| 233 | 229 |
//start the container |
| 234 | 230 |
if err := cli.client.ContainerStart(createResponse.ID); err != nil {
|