|
7 | 7 | "path/filepath" |
8 | 8 |
|
9 | 9 | "github.com/opencontainers/runc/libcontainer" |
| 10 | + "github.com/opencontainers/runc/libcontainer/configs" |
10 | 11 | "github.com/urfave/cli" |
11 | 12 | ) |
12 | 13 |
|
@@ -58,24 +59,27 @@ status of "ubuntu01" as "stopped" the following will delete resources held for |
58 | 59 | } |
59 | 60 | return err |
60 | 61 | } |
61 | | - // When --force is given, we kill all container processes and |
62 | | - // then destroy the container. This is done even for a stopped |
63 | | - // container, because (in case it does not have its own PID |
64 | | - // namespace) there may be some leftover processes in the |
65 | | - // container's cgroup. |
66 | | - if force { |
67 | | - return killAndDestroy(container) |
68 | | - } |
69 | 62 | s, err := container.Status() |
70 | 63 | if err != nil { |
71 | 64 | return err |
72 | 65 | } |
73 | 66 | switch s { |
74 | 67 | case libcontainer.Stopped: |
| 68 | + // For a stopped container, because (in case it does not have |
| 69 | + // its own PID namespace) there may be some leftover processes |
| 70 | + // in the container's cgroup. |
| 71 | + if !container.Config().Namespaces.IsPrivate(configs.NEWPID) { |
| 72 | + return killAndDestroy(container) |
| 73 | + } |
75 | 74 | return container.Destroy() |
76 | 75 | case libcontainer.Created: |
77 | 76 | return killAndDestroy(container) |
78 | 77 | default: |
| 78 | + // When --force is given, we kill all container processes and |
| 79 | + // then destroy the container. |
| 80 | + if force { |
| 81 | + return killAndDestroy(container) |
| 82 | + } |
79 | 83 | return fmt.Errorf("cannot delete container %s that is not stopped: %s", id, s) |
80 | 84 | } |
81 | 85 | }, |
|
0 commit comments