@@ -13,6 +13,18 @@ import (
1313 "github.com/urfave/cli"
1414)
1515
16+ func killContainer (container libcontainer.Container ) error {
17+ container .Signal (syscall .SIGKILL )
18+ for i := 0 ; i < 100 ; i ++ {
19+ time .Sleep (100 * time .Millisecond )
20+ if err := container .Signal (syscall .Signal (0 )); err != nil {
21+ destroy (container )
22+ return nil
23+ }
24+ }
25+ return fmt .Errorf ("container init still running" )
26+ }
27+
1628var deleteCommand = cli.Command {
1729 Name : "delete" ,
1830 Usage : "delete any resources held by the container often used with detached containers" ,
@@ -23,9 +35,15 @@ Where "<container-id>" is the name for the instance of the container.
2335EXAMPLE:
2436For example, if the container id is "ubuntu01" and runc list currently shows the
2537status of "ubuntu01" as "stopped" the following will delete resources held for
26- "ubuntu01" removing "ubuntu01" from the runc list of containers:
27-
38+ "ubuntu01" removing "ubuntu01" from the runc list of containers:
39+
2840 # runc delete ubuntu01` ,
41+ Flags : []cli.Flag {
42+ cli.BoolFlag {
43+ Name : "force, f" ,
44+ Usage : "Forcibly kills the container if it is still running" ,
45+ },
46+ },
2947 Action : func (context * cli.Context ) error {
3048 container , err := getContainer (context )
3149 if err != nil {
@@ -47,16 +65,11 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
4765 case libcontainer .Stopped :
4866 destroy (container )
4967 case libcontainer .Created :
50- container .Signal (syscall .SIGKILL )
51- for i := 0 ; i < 100 ; i ++ {
52- time .Sleep (100 * time .Millisecond )
53- if err := container .Signal (syscall .Signal (0 )); err != nil {
54- destroy (container )
55- return nil
56- }
57- }
58- return fmt .Errorf ("container init still running" )
68+ return killContainer (container )
5969 default :
70+ if context .Bool ("force" ) {
71+ return killContainer (container )
72+ }
6073 return fmt .Errorf ("cannot delete container that is not stopped: %s" , s )
6174 }
6275 return nil
0 commit comments