You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And explain how the handling differs when a new start-call joins an
existing container vs. creating a new container. This is spun off
from the mailing list thread now that that's settled down [1].
This write-up is just about Linux containers, since I don't understand
the other systems well enough to do them justice.
[1]: https://groups.google.com/a/opencontainers.org/forum/#!topic/dev/frUXLljXy8Y
Message-ID: <20150915034717.GO18018@odin.tremily.us>
Signed-off-by: W. Trevor King <wking@tremily.us>
Copy file name to clipboardExpand all lines: runtime-config.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,11 @@ Hook paths are absolute and are executed from the host's filesystem.
18
18
19
19
### Pre-start
20
20
21
-
The pre-start hooks are called after the container process is spawned, but before the user supplied command is executed.
21
+
The pre-start hooks are called [after the container process is spawned, but before the user supplied command is executed](runtime.md#typical-lifecycle).
22
22
They are called after the container namespaces are created on Linux, so they provide an opportunity to customize the container.
23
23
In Linux, for e.g., the network namespace could be configured in this hook.
24
24
25
-
If a hook returns a non-zero exit code, then an error including the exit code and the stderr is returned to the caller and the container is torn down.
25
+
If a hook returns a non-zero exit code, [then an error including the exit code and the stderr is returned to the caller and the container is torn down](runtime.md#typical-lifecycle).
26
26
27
27
### Post-start
28
28
@@ -33,7 +33,7 @@ If a hook returns a non-zero exit code, then an error is logged and the remainin
33
33
34
34
### Post-stop
35
35
36
-
The post-stop hooks are called after the container process is stopped.
36
+
The post-stop hooks are called [after the container process is stopped](runtime.md#typical-lifecycle).
37
37
Cleanup or debugging could be performed in such a hook.
38
38
If a hook returns a non-zero exit code, then an error is logged and the remaining hooks are executed.
Copy file name to clipboardExpand all lines: runtime.md
+44-9Lines changed: 44 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,24 +29,59 @@ The root directory to the bundle is provided in the state so that consumers can
29
29
}
30
30
```
31
31
32
-
## Lifecycle
32
+
## Typical lifecycle
33
+
34
+
A typical lifecyle progresses like this:
35
+
36
+
1. There is no container
37
+
2. A user tells the runtime to start a container and launch a process inside it
38
+
3. The runtime [creates the container](#create)
39
+
4. The runtime executes any [pre-start hooks](runtime-config.md#pre-start)
40
+
5. The runtime [executes the container process](#start-process)
41
+
6. The container process is running
42
+
7. A user tells the runtime to send a termination signal to the container process
43
+
8. The runtime [sends a termination signal to the container process](#stop-process)
44
+
9. The container process exits
45
+
10. The runtime [terminates any other processes in the container](#stop-process)
46
+
11. The runtime executes any [post-stop hooks](runtime-config.md#post-stop)
47
+
12. The runtime [removes the container](#cleanup)
48
+
49
+
With steps 7 and 8, the user is explicitly stopping the container process (via the runtime), but it's also possible that the container process could exit for other reasons.
50
+
In that case we skip directly from 6 to [10](#stop-process).
51
+
52
+
Failure in a pre-start hook or other setup task can cause a jump straight to [11](runtime-config.md#post-stop).
33
53
34
54
### Create
35
55
36
-
Creates the container: file system, namespaces, cgroups, capabilities.
56
+
Create the container: file system, namespaces, cgroups, capabilities, etc.
57
+
The invoked process forks, with one branch that stays in the host namespace and another that enters the container.
58
+
The host process carries out all container setup actions, and continues running for the life of the container so it can perform teardown after the container process exits.
59
+
The container process changes users and drops privileges in preparation for the container process start.
60
+
At this point, the host process writes the [`state.json`](#state) file with the host-side version of the container-process's PID (the container process may be in a PID namespace).
37
61
38
62
### Start (process)
39
63
40
-
Runs a process in a container.
41
-
Can be invoked several times.
64
+
After the pre-start hooks complete, the host process signals the container process to execute the runtime.
65
+
The runtime execs the process defined in `config.json`'s [**`process`** attribute](config.md#process-configuration).
66
+
On Linux hosts, some information for this execution may come from outside the `config.json` and `runtime.json` specifications.
67
+
See the [Linux-specific notes for details](runtime-linux.md#file-descriptors).
42
68
43
69
### Stop (process)
44
70
45
-
Not sure we need that from runc cli.
46
-
Process is killed from the outside.
71
+
Send a termination signal to the container process (can optionally send other signals to the container process, e.g. a kill signal).
72
+
When the process exits, the host process collects it's exit status to return as its own exit status.
73
+
If there are any remaining processes in the container's cgroup (and [we only support unified-hierarchies](runtime-config-linux.md#control-groups)), the host process kills and reaps them.
74
+
75
+
### Cleanup
76
+
77
+
The host process removes the [`state.json`](#state) file and the container: unmounting file systems, removing namespaces, etc.
78
+
This is the inverse of create.
79
+
The host process then exits with the container processes's exit status.
47
80
48
-
This event needs to be captured by runc to run onstop event handlers.
81
+
## Joining existing containers
49
82
50
-
## Hooks
83
+
Joining an existing container looks just like the usual workflow, except that the container process [joins the target container](runtime-config-linux.md#control-groups) at the beginning of step 3.
84
+
It can then, depending on its configuration, continue to create an additional child cgroup underneath the one it joined.
51
85
52
-
See [runtime configuration for hooks](./runtime-config.md)
86
+
When exiting, the reaping logic in the [stop phase](#stop-process) is the same.
87
+
If the container process created a child cgroup, all other processes in that child cgroup are reaped, but no other processes in the joined cgroup (which the container process did not create) are reaped.
0 commit comments