Skip to content

Commit b144f3d

Browse files
authored
Merge pull request opencontainers#2825 from lifubang/nodelete
proposal: add --keep to runc run
2 parents 0d193ed + 0f94799 commit b144f3d

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

man/runc-run.8.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ container to inherit the calling processes session key.
4242
: Pass _N_ additional file descriptors to the container (**stdio** +
4343
**$LISTEN_FDS** + _N_ in total). Default is **0**.
4444

45+
**--keep**
46+
: Keep container's state directory and cgroup. This can be helpful if a user
47+
wants to check the state (e.g. of cgroup controllers) after the container has
48+
exited. If this option is used, a manual **runc delete** is needed afterwards
49+
to clean an exited container's artefacts.
50+
4551
# SEE ALSO
4652

4753
**runc**(8).

run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
4040
Name: "detach, d",
4141
Usage: "detach from the container's process",
4242
},
43+
cli.BoolFlag{
44+
Name: "keep",
45+
Usage: "do not delete the container after it exits",
46+
},
4347
cli.StringFlag{
4448
Name: "pid-file",
4549
Value: "",

tests/integration/run.bats

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
function setup() {
6+
setup_hello
7+
}
8+
9+
function teardown() {
10+
teardown_bundle
11+
}
12+
13+
@test "runc run" {
14+
runc run test_hello
15+
[ "$status" -eq 0 ]
16+
17+
runc state test_hello
18+
[ "$status" -ne 0 ]
19+
}
20+
21+
@test "runc run --keep" {
22+
runc run --keep test_run_keep
23+
[ "$status" -eq 0 ]
24+
25+
testcontainer test_run_keep stopped
26+
27+
runc state test_run_keep
28+
[ "$status" -eq 0 ]
29+
30+
runc delete test_run_keep
31+
32+
runc state test_run_keep
33+
[ "$status" -ne 0 ]
34+
}
35+
36+
@test "runc run --keep (check cgroup exists)" {
37+
# for systemd driver, the unit's cgroup path will be auto removed if container's all processes exited
38+
requires no_systemd
39+
40+
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
41+
42+
set_cgroups_path
43+
44+
runc run --keep test_run_keep
45+
[ "$status" -eq 0 ]
46+
47+
testcontainer test_run_keep stopped
48+
49+
runc state test_run_keep
50+
[ "$status" -eq 0 ]
51+
52+
# check that cgroup exists
53+
check_cgroup_value "pids.max" "max"
54+
55+
runc delete test_run_keep
56+
57+
runc state test_run_keep
58+
[ "$status" -ne 0 ]
59+
}

utils_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func startContainer(context *cli.Context, spec *specs.Spec, action CtAct, criuOp
439439

440440
r := &runner{
441441
enableSubreaper: !context.Bool("no-subreaper"),
442-
shouldDestroy: true,
442+
shouldDestroy: !context.Bool("keep"),
443443
container: container,
444444
listenFDs: listenFDs,
445445
notifySocket: notifySocket,

0 commit comments

Comments
 (0)