Docker-DCO-1.1-Signed-off-by: Adrien Folie <folie.adrien@gmail.com> (github: folieadrien)
| ... | ... |
@@ -983,7 +983,8 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
| 983 | 983 |
cmd := cli.Subcmd("rm", "[OPTIONS] CONTAINER [CONTAINER...]", "Remove one or more containers")
|
| 984 | 984 |
v := cmd.Bool([]string{"v", "-volumes"}, false, "Remove the volumes associated with the container")
|
| 985 | 985 |
link := cmd.Bool([]string{"l", "#link", "-link"}, false, "Remove the specified link and not the underlying container")
|
| 986 |
- force := cmd.Bool([]string{"f", "-force"}, false, "Force removal of running container")
|
|
| 986 |
+ stop := cmd.Bool([]string{"#f", "s", "#-force", "-stop"}, false, "Stop and remove a running container")
|
|
| 987 |
+ kill := cmd.Bool([]string{"k", "-kill"}, false, "Kill and remove a running container")
|
|
| 987 | 988 |
|
| 988 | 989 |
if err := cmd.Parse(args); err != nil {
|
| 989 | 990 |
return nil |
| ... | ... |
@@ -992,6 +993,9 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
| 992 | 992 |
cmd.Usage() |
| 993 | 993 |
return nil |
| 994 | 994 |
} |
| 995 |
+ if *stop && *kill {
|
|
| 996 |
+ return fmt.Errorf("Conflicting options: -s/--stop and -k/--kill")
|
|
| 997 |
+ } |
|
| 995 | 998 |
val := url.Values{}
|
| 996 | 999 |
if *v {
|
| 997 | 1000 |
val.Set("v", "1")
|
| ... | ... |
@@ -999,8 +1003,11 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
| 999 | 999 |
if *link {
|
| 1000 | 1000 |
val.Set("link", "1")
|
| 1001 | 1001 |
} |
| 1002 |
- if *force {
|
|
| 1003 |
- val.Set("force", "1")
|
|
| 1002 |
+ if *stop {
|
|
| 1003 |
+ val.Set("stop", "1")
|
|
| 1004 |
+ } |
|
| 1005 |
+ if *kill {
|
|
| 1006 |
+ val.Set("kill", "1")
|
|
| 1004 | 1007 |
} |
| 1005 | 1008 |
|
| 1006 | 1009 |
var encounteredError error |
| ... | ... |
@@ -678,9 +678,19 @@ func deleteContainers(eng *engine.Engine, version version.Version, w http.Respon |
| 678 | 678 |
return fmt.Errorf("Missing parameter")
|
| 679 | 679 |
} |
| 680 | 680 |
job := eng.Job("container_delete", vars["name"])
|
| 681 |
+ |
|
| 682 |
+ if version.GreaterThanOrEqualTo("1.14") {
|
|
| 683 |
+ job.Setenv("stop", r.Form.Get("stop"))
|
|
| 684 |
+ job.Setenv("kill", r.Form.Get("kill"))
|
|
| 685 |
+ |
|
| 686 |
+ if job.GetenvBool("stop") && job.GetenvBool("kill") {
|
|
| 687 |
+ return fmt.Errorf("Bad parameters: can't use stop and kill simultaneously")
|
|
| 688 |
+ } |
|
| 689 |
+ } else {
|
|
| 690 |
+ job.Setenv("stop", r.Form.Get("force"))
|
|
| 691 |
+ } |
|
| 681 | 692 |
job.Setenv("removeVolume", r.Form.Get("v"))
|
| 682 | 693 |
job.Setenv("removeLink", r.Form.Get("link"))
|
| 683 |
- job.Setenv("forceRemove", r.Form.Get("force"))
|
|
| 684 | 694 |
if err := job.Run(); err != nil {
|
| 685 | 695 |
return err |
| 686 | 696 |
} |
| ... | ... |
@@ -1787,7 +1787,8 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
|
| 1787 | 1787 |
name := job.Args[0] |
| 1788 | 1788 |
removeVolume := job.GetenvBool("removeVolume")
|
| 1789 | 1789 |
removeLink := job.GetenvBool("removeLink")
|
| 1790 |
- forceRemove := job.GetenvBool("forceRemove")
|
|
| 1790 |
+ stop := job.GetenvBool("stop")
|
|
| 1791 |
+ kill := job.GetenvBool("kill")
|
|
| 1791 | 1792 |
|
| 1792 | 1793 |
container := srv.daemon.Get(name) |
| 1793 | 1794 |
|
| ... | ... |
@@ -1821,12 +1822,16 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
|
| 1821 | 1821 |
|
| 1822 | 1822 |
if container != nil {
|
| 1823 | 1823 |
if container.State.IsRunning() {
|
| 1824 |
- if forceRemove {
|
|
| 1824 |
+ if stop {
|
|
| 1825 | 1825 |
if err := container.Stop(5); err != nil {
|
| 1826 | 1826 |
return job.Errorf("Could not stop running container, cannot remove - %v", err)
|
| 1827 | 1827 |
} |
| 1828 |
+ } else if kill {
|
|
| 1829 |
+ if err := container.Kill(); err != nil {
|
|
| 1830 |
+ return job.Errorf("Could not kill running container, cannot remove - %v", err)
|
|
| 1831 |
+ } |
|
| 1828 | 1832 |
} else {
|
| 1829 |
- return job.Errorf("Impossible to remove a running container, please stop it first or use -f")
|
|
| 1833 |
+ return job.Errorf("You cannot remove a running container. Stop the container before attempting removal or use -s or -k")
|
|
| 1830 | 1834 |
} |
| 1831 | 1835 |
} |
| 1832 | 1836 |
if err := srv.daemon.Destroy(container); err != nil {
|