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
Hooks are only valid in runtime.json, so we should discuss them in the
runtime.json docs. I'll add appropriate links from the lifecycle docs
in a bit, but linking into runtime.json is poor enough that I think it
deserves its own commit. The only change here besides the copy/paste
is the addition of a blank line after the Markdown headers to match
the rest of the documentation.
Signed-off-by: W. Trevor King <[email protected]>
Copy file name to clipboardExpand all lines: runtime.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,48 @@
1
+
## Hooks
2
+
3
+
Hooks allow one to run code before/after various lifecycle events of the container.
4
+
The state of the container is passed to the hooks over stdin, so the hooks could get the information they need to do their work.
5
+
6
+
Hook paths are absolute and are executed from the host's filesystem.
7
+
8
+
### Pre-start
9
+
10
+
The pre-start hooks are called after the container process is spawned, but before the user supplied command is executed.
11
+
They are called after the container namespaces are created on Linux, so they provide an opportunity to customize the container.
12
+
In Linux, for e.g., the network namespace could be configured in this hook.
13
+
14
+
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.
15
+
16
+
### Post-stop
17
+
18
+
The post-stop hooks are called after the container process is stopped. Cleanup or debugging could be performed in such a hook.
19
+
If a hook returns a non-zero exit code, then an error is logged and the remaining hooks are executed.
20
+
21
+
*Example*
22
+
23
+
```json
24
+
"hooks" : {
25
+
"prestart": [
26
+
{
27
+
"path": "/usr/bin/fix-mounts",
28
+
"args": ["arg1", "arg2"],
29
+
"env": [ "key1=value1"]
30
+
},
31
+
{
32
+
"path": "/usr/bin/setup-network"
33
+
}
34
+
],
35
+
"poststop": [
36
+
{
37
+
"path": "/usr/sbin/cleanup.sh",
38
+
"args": ["-f"]
39
+
}
40
+
]
41
+
}
42
+
```
43
+
44
+
`path` is required for a hook. `args` and `env` are optional.
45
+
1
46
## Mount Configuration
2
47
3
48
Additional filesystems can be declared as "mounts", specified in the *mounts* array. The parameters are similar to the ones in Linux mount system call. [http://linux.die.net/man/2/mount](http://linux.die.net/man/2/mount)
0 commit comments