-
Notifications
You must be signed in to change notification settings - Fork 611
Expand file tree
/
Copy pathruntime.md
More file actions
146 lines (107 loc) · 9.43 KB
/
runtime.md
File metadata and controls
146 lines (107 loc) · 9.43 KB
Edit and raw actions
OlderNewer
1
# <a name="runtimeAndLifecycle" />Runtime and Lifecycle
2
3
## <a name="runtimeScopeContainer" />Scope of a Container
4
5
Barring access control concerns, the entity using a runtime to create a container MUST be able to use the operations defined in this specification against that same container.
6
Whether other entities using the same, or other, instance of the runtime can see that container is out of scope of this specification.
7
8
## <a name="runtimeState" />State
9
10
The state of a container includes the following properties:
11
12
* **`ociVersion`** (string, REQUIRED) is the OCI specification version used when creating the container.
13
* **`id`** (string, REQUIRED) is the container's ID.
14
This MUST be unique across all containers on this host.
15
There is no requirement that it be unique across hosts.
16
* **`status`** (string, REQUIRED) is the runtime state of the container.
17
The value MAY be one of:
18
19
* `creating`: the container is being created (step 2 in the [lifecycle](#lifecycle))
20
* `created`: the runtime has finished the [create operation](#create) (after step 2 in the [lifecycle](#lifecycle)), and the container process has neither exited nor executed the user-specified program
21
* `running`: the container process has executed the user-specified program but has not exited (after step 4 in the [lifecycle](#lifecycle))
22
* `stopped`: the container process has exited (step 5 in the [lifecycle](#lifecycle))
23
24
Additional values MAY be defined by the runtime, however, they MUST be used to represent new runtime states not defined above.
25
* **`pid`** (int, REQUIRED when `status` is `created` or `running`) is the ID of the container process, as seen by the host.
26
* **`bundle`** (string, REQUIRED) is the absolute path to the container's bundle directory.
27
This is provided so that consumers can find the container's configuration and root filesystem on the host.
28
* **`annotations`** (map, OPTIONAL) contains the list of annotations associated with the container.
29
If no annotations were provided then this property MAY either be absent or an empty map.
30
31
The state MAY include additional properties.
32
33
When serialized in JSON, the format MUST adhere to the following pattern:
34
35
```json
36
{
37
"ociVersion": "0.2.0",
38
"id": "oci-container1",
39
"status": "running",
40
"pid": 4422,
41
"bundle": "/containers/redis",
42
"annotations": {
43
"myKey": "myValue"
44
}
45
}
46
```
47
48
See [Query State](#query-state) for information on retrieving the state of a container.
49
50
## <a name="runtimeLifecycle" />Lifecycle
51
The lifecycle describes the timeline of events that happen from when a container is created to when it ceases to exist.
52
53
1. OCI compliant runtime's [`create`](runtime.md#create) command is invoked with a reference to the location of the bundle and a unique identifier.
54
2. The container's runtime environment MUST be created according to the configuration in [`config.json`](config.md).
55
If the runtime is unable to create the environment specified in the [`config.json`](config.md), it MUST [generate an error](#errors).
56
While the resources requested in the [`config.json`](config.md) MUST be created, the user-specified program (from [`process`](config.md#process)) MUST NOT be run at this time.
57
Any updates to [`config.json`](config.md) after this step MUST NOT affect the container.
58
3. Once the container is created additional actions MAY be performed based on the features the runtime chooses to support.
59
However, some actions might only be available based on the current state of the container (e.g. only available while it is started).
60
4. Runtime's [`start`](runtime.md#start) command is invoked with the unique identifier of the container.
61
5. The [prestart hooks](config.md#prestart) MUST be invoked by the runtime.
62
If any prestart hook fails, the runtime MUST [generate an error](#errors), stop the container, and continue the lifecycle at step 10.
63
6. The runtime MUST run the user-specified program, as specified by [`process`](config.md#process).
64
7. The [poststart hooks](config.md#poststart) MUST be invoked by the runtime.
65
If any poststart hook fails, the runtime MUST [log a warning](#warnings), but the remaining hooks and lifecycle continue as if the hook had succeeded.
66
8. The container process exits.
67
This MAY happen due to erroring out, exiting, crashing or the runtime's [`kill`](runtime.md#kill) operation being invoked.
68
9. Runtime's [`delete`](runtime.md#delete) command is invoked with the unique identifier of the container.
69
10. The container MUST be destroyed by undoing the steps performed during create phase (step 2).
70
11. The [poststop hooks](config.md#poststop) MUST be invoked by the runtime.
71
If any poststop hook fails, the runtime MUST [log a warning](#warnings), but the remaining hooks and lifecycle continue as if the hook had succeeded.
72
73
## <a name="runtimeErrors" />Errors
74
75
In cases where the specified operation generates an error, this specification does not mandate how, or even if, that error is returned or exposed to the user of an implementation.
76
Unless otherwise stated, generating an error MUST leave the state of the environment as if the operation were never attempted - modulo any possible trivial ancillary changes such as logging.
77
78
## <a name="runtimeWarnings" />Warnings
79
80
In cases where the specified operation logs a warning, this specification does not mandate how, or even if, that warning is returned or exposed to the user of an implementation.
81
Unless otherwise stated, logging a warning does not change the flow of the operation; it MUST continue as if the warning had not been logged.
82
83
## <a name="runtimeOperations" />Operations
84
85
OCI compliant runtimes MUST support the following operations, unless the operation is not supported by the base operating system.
86
87
Note: these operations are not specifying any command-line APIs, and the parameters are inputs for general operations.
88
89
### <a name="runtimeQueryState" />Query State
90
91
`state <container-id>`
92
93
This operation MUST [generate an error](#errors) if it is not provided the ID of a container.
94
Attempting to query a container that does not exist MUST [generate an error](#errors).
95
This operation MUST return the state of a container as specified in the [State](#state) section.
96
97
### <a name="runtimeCreate" />Create
98
99
`create <container-id> <path-to-bundle>`
100
101
This operation MUST [generate an error](#errors) if it is not provided a path to the bundle and the container ID to associate with the container.
102
If the ID provided is not unique across all containers within the scope of the runtime, or is not valid in any other way, the implementation MUST [generate an error](#errors) and a new container MUST NOT be created.
103
Using the data in [`config.json`](config.md), this operation MUST create a new container.
104
This means that all of the resources associated with the container MUST be created, however, the user-specified program MUST NOT be run at this time.
105
If the runtime cannot create the container as specified in [`config.json`](config.md), it MUST [generate an error](#errors) and a new container MUST NOT be created.
106
107
Upon successful completion of this operation the `status` property of this container MUST be `created`.
108
109
The runtime MAY validate `config.json` against this spec, either generically or with respect to the local system capabilities, before creating the container ([step 2](#lifecycle)).
110
Runtime callers who are interested in pre-create validation can run [bundle-validation tools](implementations.md#testing--tools) before invoking the create operation.
111
112
Any changes made to the [`config.json`](config.md) file after this operation will not have an effect on the container.
113
114
### <a name="runtimeStart" />Start
115
`start <container-id>`
116
117
This operation MUST [generate an error](#errors) if it is not provided the container ID.
118
Attempting to start a container that does not exist MUST [generate an error](#errors).
119
Attempting to start an already started container MUST have no effect on the container and MUST [generate an error](#errors).
120
This operation MUST run the user-specified program as specified by [`process`](config.md#process).
121
122
Upon successful completion of this operation the `status` property of this container MUST be `running`.
123
124
### <a name="runtimeKill" />Kill
125
`kill <container-id> <signal>`
126
127
This operation MUST [generate an error](#errors) if it is not provided the container ID.
128
Attempting to send a signal to a container that is not running MUST have no effect on the container and MUST [generate an error](#errors).
129
This operation MUST send the specified signal to the process in the container.
130
131
When the process in the container is stopped, irrespective of it being as a result of a `kill` operation or any other reason, the `status` property of this container MUST be `stopped`.
132
133
### <a name="runtimeDelete" />Delete
134
`delete <container-id>`
135
136
This operation MUST [generate an error](#errors) if it is not provided the container ID.
137
Attempting to delete a container that does not exist MUST [generate an error](#errors).
138
Attempting to delete a container whose process is still running MUST [generate an error](#errors).
139
Deleting a container MUST delete the resources that were created during the `create` step.
140
Note that resources associated with the container, but not created by this container, MUST NOT be deleted.
141
Once a container is deleted its ID MAY be used by a subsequent container.
142
143
144
## <a name="runtimeHooks" />Hooks
145
Many of the operations specified in this specification have "hooks" that allow for additional actions to be taken before or after each operation.
146
See [runtime configuration for hooks](./config.md#hooks) for more information.