Stop/Kill options for containers removal

Docker-DCO-1.1-Signed-off-by: Adrien Folie <folie.adrien@gmail.com> (github: folieadrien)
This commit is contained in:
Adrien Folie
2014-07-11 23:26:08 +00:00
committed by Victor Vieux
parent d53db040c8
commit 7810070630
3 changed files with 29 additions and 7 deletions
+10 -3
View File
@@ -983,7 +983,8 @@ func (cli *DockerCli) CmdRm(args ...string) error {
cmd := cli.Subcmd("rm", "[OPTIONS] CONTAINER [CONTAINER...]", "Remove one or more containers")
v := cmd.Bool([]string{"v", "-volumes"}, false, "Remove the volumes associated with the container")
link := cmd.Bool([]string{"l", "#link", "-link"}, false, "Remove the specified link and not the underlying container")
force := cmd.Bool([]string{"f", "-force"}, false, "Force removal of running container")
stop := cmd.Bool([]string{"#f", "s", "#-force", "-stop"}, false, "Stop and remove a running container")
kill := cmd.Bool([]string{"k", "-kill"}, false, "Kill and remove a running container")
if err := cmd.Parse(args); err != nil {
return nil
@@ -992,6 +993,9 @@ func (cli *DockerCli) CmdRm(args ...string) error {
cmd.Usage()
return nil
}
if *stop && *kill {
return fmt.Errorf("Conflicting options: -s/--stop and -k/--kill")
}
val := url.Values{}
if *v {
val.Set("v", "1")
@@ -999,8 +1003,11 @@ func (cli *DockerCli) CmdRm(args ...string) error {
if *link {
val.Set("link", "1")
}
if *force {
val.Set("force", "1")
if *stop {
val.Set("stop", "1")
}
if *kill {
val.Set("kill", "1")
}
var encounteredError error
+11 -1
View File
@@ -678,9 +678,19 @@ func deleteContainers(eng *engine.Engine, version version.Version, w http.Respon
return fmt.Errorf("Missing parameter")
}
job := eng.Job("container_delete", vars["name"])
if version.GreaterThanOrEqualTo("1.14") {
job.Setenv("stop", r.Form.Get("stop"))
job.Setenv("kill", r.Form.Get("kill"))
if job.GetenvBool("stop") && job.GetenvBool("kill") {
return fmt.Errorf("Bad parameters: can't use stop and kill simultaneously")
}
} else {
job.Setenv("stop", r.Form.Get("force"))
}
job.Setenv("removeVolume", r.Form.Get("v"))
job.Setenv("removeLink", r.Form.Get("link"))
job.Setenv("forceRemove", r.Form.Get("force"))
if err := job.Run(); err != nil {
return err
}