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

Revert rm -f deprecation use SIGKILL instead

`rm -f` was originally deprecated in favor of `rm --stop/--kill` since `rm
-f` was sending SIGTERM and potentially very slow.
Instead this will bring back `rm -f` but use SIGKILL isntead

Docker-DCO-1.1-Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
This commit is contained in:
Brian Goff 2014-08-07 14:50:59 -04:00
parent 140e6abb17
commit 95f86da641
9 changed files with 18 additions and 104 deletions

View file

@ -1016,8 +1016,7 @@ func (cli *DockerCli) CmdRm(args ...string) error {
cmd := cli.Subcmd("rm", "[OPTIONS] CONTAINER [CONTAINER...]", "Remove one or more containers") 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") 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") link := cmd.Bool([]string{"l", "#link", "-link"}, false, "Remove the specified link and not the underlying container")
stop := cmd.Bool([]string{"#f", "s", "#-force", "-stop"}, false, "Stop and remove a running container") force := cmd.Bool([]string{"f", "-force"}, false, "Force the removal of a running container (uses SIGKILL)")
kill := cmd.Bool([]string{"k", "-kill"}, false, "Kill and remove a running container")
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {
return nil return nil
@ -1026,9 +1025,7 @@ func (cli *DockerCli) CmdRm(args ...string) error {
cmd.Usage() cmd.Usage()
return nil return nil
} }
if *stop && *kill {
return fmt.Errorf("Conflicting options: -s/--stop and -k/--kill")
}
val := url.Values{} val := url.Values{}
if *v { if *v {
val.Set("v", "1") val.Set("v", "1")
@ -1036,11 +1033,9 @@ func (cli *DockerCli) CmdRm(args ...string) error {
if *link { if *link {
val.Set("link", "1") val.Set("link", "1")
} }
if *stop {
val.Set("stop", "1") if *force {
} val.Set("force", "1")
if *kill {
val.Set("kill", "1")
} }
var encounteredError error var encounteredError error

View file

@ -680,16 +680,8 @@ func deleteContainers(eng *engine.Engine, version version.Version, w http.Respon
} }
job := eng.Job("delete", vars["name"]) job := eng.Job("delete", vars["name"])
if version.GreaterThanOrEqualTo("1.14") { job.Setenv("forceRemove", r.Form.Get("force"))
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("removeVolume", r.Form.Get("v"))
job.Setenv("removeLink", r.Form.Get("link")) job.Setenv("removeLink", r.Form.Get("link"))
if err := job.Run(); err != nil { if err := job.Run(); err != nil {

View file

@ -474,30 +474,6 @@ func TestDeleteContainers(t *testing.T) {
} }
} }
func TestDeleteContainersWithStopAndKill(t *testing.T) {
if api.APIVERSION.LessThan("1.14") {
return
}
eng := engine.New()
var called bool
eng.Register("delete", func(job *engine.Job) engine.Status {
called = true
return engine.StatusOK
})
r := serveRequest("DELETE", "/containers/foo?stop=1&kill=1", nil, eng, t)
if r.Code != http.StatusBadRequest {
t.Fatalf("Got status %d, expected %d", r.Code, http.StatusBadRequest)
}
if called {
t.Fatalf("container_delete jobs was called, but it shouldn't")
}
res := strings.TrimSpace(r.Body.String())
expected := "Bad parameters: can't use stop and kill simultaneously"
if !strings.Contains(res, expected) {
t.Fatalf("Output %s, expected %s in it", res, expected)
}
}
func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t *testing.T) *httptest.ResponseRecorder { func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t *testing.T) *httptest.ResponseRecorder {
return serveRequestUsingVersion(method, target, api.APIVERSION, body, eng, t) return serveRequestUsingVersion(method, target, api.APIVERSION, body, eng, t)
} }

View file

@ -20,9 +20,7 @@ func (daemon *Daemon) ContainerDestroy(job *engine.Job) engine.Status {
name := job.Args[0] name := job.Args[0]
removeVolume := job.GetenvBool("removeVolume") removeVolume := job.GetenvBool("removeVolume")
removeLink := job.GetenvBool("removeLink") removeLink := job.GetenvBool("removeLink")
stop := job.GetenvBool("stop") forceRemove := job.GetenvBool("forceRemove")
kill := job.GetenvBool("kill")
container := daemon.Get(name) container := daemon.Get(name)
if removeLink { if removeLink {
@ -55,11 +53,7 @@ func (daemon *Daemon) ContainerDestroy(job *engine.Job) engine.Status {
if container != nil { if container != nil {
if container.State.IsRunning() { if container.State.IsRunning() {
if stop { if forceRemove {
if err := container.Stop(5); err != nil {
return job.Errorf("Could not stop running container, cannot remove - %v", err)
}
} else if kill {
if err := container.Kill(); err != nil { if err := container.Kill(); err != nil {
return job.Errorf("Could not kill running container, cannot remove - %v", err) return job.Errorf("Could not kill running container, cannot remove - %v", err)
} }

View file

@ -6,9 +6,8 @@ docker-rm - Remove one or more containers
# SYNOPSIS # SYNOPSIS
**docker rm** **docker rm**
[**-k**|**--kill**[=*false*]]
[**-l**|**--link**[=*false*]] [**-l**|**--link**[=*false*]]
[**-s**|**--stop**[=*false*]] [**-f**|**--force**[=*false*]]
[**-v**|**--volumes**[=*false*]] [**-v**|**--volumes**[=*false*]]
CONTAINER [CONTAINER...] CONTAINER [CONTAINER...]
@ -20,15 +19,11 @@ remove a running container unless you use the \fB-f\fR option. To see all
containers on a host use the **docker ps -a** command. containers on a host use the **docker ps -a** command.
# OPTIONS # OPTIONS
**-k**, **--kill**=*true*|*false*
Kill and remove a running container. The default is *false*.
**-l**, **--link**=*true*|*false* **-l**, **--link**=*true*|*false*
Remove the specified link and not the underlying container. The default is *false*. Remove the specified link and not the underlying container. The default is *false*.
**-s**, **--stop**=*true*|*false* **-f**, **--force**=*true*|*false*
Stop and remove a running container. The default is *false*. Allows removing of a running container by first killing it with SIGKILL.
**-v**, **--volumes**=*true*|*false* **-v**, **--volumes**=*true*|*false*
Remove the volumes associated with the container. The default is *false*. Remove the volumes associated with the container. The default is *false*.

View file

@ -37,11 +37,7 @@ You can still call an old version of the API using
`DELETE /containers/(id)` `DELETE /containers/(id)`
**New!** **New!**
You can now use the `stop` parameter to stop running containers before removal When using `force`, the container will be immediately killed with SIGKILL.
(replace `force`).
**New!**
You can now use the `kill` parameter to kill running containers before removal.
`POST /containers/(id)/start` `POST /containers/(id)/start`

View file

@ -679,9 +679,7 @@ Remove the container `id` from the filesystem
- **v** 1/True/true or 0/False/false, Remove the volumes - **v** 1/True/true or 0/False/false, Remove the volumes
associated to the container. Default false associated to the container. Default false
- **stop** 1/True/true or 0/False/false, Stop then remove the container. - **force** - 1/True/true or 0/False/false, Kill then remove the container.
Default false
- **kill** - 1/True/true or 0/False/false, Kill then remove the container.
Default false Default false
Status Codes: Status Codes:

View file

@ -864,8 +864,7 @@ registry or to a self-hosted one.
Remove one or more containers Remove one or more containers
-s, --stop=false Stop and remove a running container -f, --force=false Force removal of a running container. Uses SIGKILL to stop the container.
-k, --kill=false Kill and remove a running container
-l, --link=false Remove the specified link and not the underlying container -l, --link=false Remove the specified link and not the underlying container
-v, --volumes=false Remove the volumes associated with the container -v, --volumes=false Remove the volumes associated with the container
@ -890,21 +889,12 @@ This will remove the underlying link between `/webapp`
and the `/redis` containers removing all and the `/redis` containers removing all
network communication. network communication.
$ sudo docker rm --stop redis $ sudo docker rm --force redis
redis
The main process inside the container referenced under the link `/redis` will receive
SIGTERM, and after a grace period, SIGKILL, then the container will be removed.
$ sudo docker rm --kill redis
redis redis
The main process inside the container referenced under the link `/redis` will receive The main process inside the container referenced under the link `/redis` will receive
SIGKILL, then the container will be removed. SIGKILL, then the container will be removed.
NOTE: If you try to use `stop` and `kill` simultaneously, Docker will return an error.
$ sudo docker rm $(docker ps -a -q)
This command will delete all stopped containers. The command This command will delete all stopped containers. The command
`docker ps -a -q` will return all existing container `docker ps -a -q` will return all existing container

View file

@ -57,40 +57,18 @@ func TestRemoveRunningContainer(t *testing.T) {
logDone("rm - running container") logDone("rm - running container")
} }
func TestStopAndRemoveRunningContainer(t *testing.T) { func TestForceRemoveRunningContainer(t *testing.T) {
createRunningContainer(t, "foo") createRunningContainer(t, "foo")
// Stop then remove with -s // Stop then remove with -s
cmd := exec.Command(dockerBinary, "rm", "-s", "foo") cmd := exec.Command(dockerBinary, "rm", "-f", "foo")
if _, err := runCommand(cmd); err != nil { if _, err := runCommand(cmd); err != nil {
t.Fatal(err) t.Fatal(err)
} }
deleteAllContainers() deleteAllContainers()
logDone("rm - running container with --stop=true") logDone("rm - running container with --force=true")
}
func TestKillAndRemoveRunningContainer(t *testing.T) {
createRunningContainer(t, "foo")
// Kill then remove with -k
cmd := exec.Command(dockerBinary, "rm", "-k", "foo")
if _, err := runCommand(cmd); err != nil {
t.Fatal(err)
}
deleteAllContainers()
logDone("rm - running container with --kill=true")
}
func TestRemoveContainerWithStopAndKill(t *testing.T) {
cmd := exec.Command(dockerBinary, "rm", "-sk", "foo")
if _, err := runCommand(cmd); err == nil {
t.Fatalf("Expected error: can't use stop and kill simulteanously")
}
logDone("rm - with --stop=true and --kill=true")
} }
func TestContainerOrphaning(t *testing.T) { func TestContainerOrphaning(t *testing.T) {