|
| 1 | +[[runtime]] |
| 2 | +Runtime and Lifecycle |
| 3 | +--------------------- |
| 4 | + |
| 5 | +:implementation-testing: https://github.com/opencontainers/runtime-spec/blob/master/implementations.md#testing--tools |
| 6 | + |
| 7 | +Scope of a Container |
| 8 | +~~~~~~~~~~~~~~~~~~~~ |
| 9 | + |
| 10 | +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. |
| 11 | +Whether other entities using the same, or other, instance of the runtime can see that container is out of scope of this specification. |
| 12 | + |
| 13 | +[[state]] |
| 14 | +State |
| 15 | +^^^^^ |
| 16 | + |
| 17 | +The state of a container MUST include, at least, the following properties: |
| 18 | + |
| 19 | +[[ociVersion-state,ociVersion]] |
| 20 | +`ociVersion`:: |
| 21 | + (string) is the OCI specification version `<<ociVersion-config,used when creating the container>>`. |
| 22 | + |
| 23 | +[[id,id]] `id`:: |
| 24 | + (string) is the container's ID. |
| 25 | + This MUST be unique across all containers on this host. |
| 26 | + There is no requirement that it be unique across hosts. |
| 27 | + |
| 28 | +[[status,status]] `status`:: |
| 29 | + (string) is the runtime state of the container. |
| 30 | + The value MAY be one of: |
| 31 | ++ |
| 32 | +-- |
| 33 | +[[created,created]] `created`::: |
| 34 | + The container has been created but the user-specified code has not yet been executed. |
| 35 | + |
| 36 | +[[running,running]] `running`::: |
| 37 | + The container has been created and the user-specified code is running. |
| 38 | + |
| 39 | +[[stopped,stopped]] `stopped`::: |
| 40 | + The container has been created and the user-specified code has been executed but is no longer running. |
| 41 | + |
| 42 | +Additional values MAY be defined by the runtime, however, they MUST be used to represent new runtime states not defined above. |
| 43 | +-- |
| 44 | + |
| 45 | +[[pid,pid]] `pid`:: |
| 46 | + (int) is the ID of the container process, as seen by the host. |
| 47 | + |
| 48 | +[[bundlePath,bundlePath]] `bundlePath`:: |
| 49 | + (string) is the absolute path to the container's bundle directory. |
| 50 | + This is provided so that consumers can find the container's configuration and root filesystem on the host. |
| 51 | + |
| 52 | +[[state-annotations,state annotations]] `annotations`:: |
| 53 | + (map) contains the list of annotations associated with the container. |
| 54 | + If no annotations were provided then this property MAY either be absent or an empty map. |
| 55 | + |
| 56 | +When serialized in JSON, the format MUST adhere to the following pattern: |
| 57 | + |
| 58 | +[source,json] |
| 59 | +{ |
| 60 | + "ociVersion": "0.2.0", |
| 61 | + "id": "oci-container1", |
| 62 | + "status": "running", |
| 63 | + "pid": 4422, |
| 64 | + "bundlePath": "/containers/redis", |
| 65 | + "annotations": { |
| 66 | + "myKey": "myValue" |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +See <<state-operation>> for information on retrieving the state of a container. |
| 71 | + |
| 72 | +Lifecycle |
| 73 | +~~~~~~~~~ |
| 74 | + |
| 75 | +The lifecycle describes the timeline of events that happen from when a container is created to when it ceases to exist. |
| 76 | + |
| 77 | +. [[lifecycle-create-call, step 1]] |
| 78 | + OCI compliant runtime's <<create>> command is invoked with a reference to the location of the bundle and a unique identifier. |
| 79 | + |
| 80 | +. [[lifecycle-create,step 2]] |
| 81 | + The container's runtime environment MUST be created according to the configuration in `<<config>>`. |
| 82 | + If the runtime is unable to create the environment specified in the `<<config>>`, it MUST generate an error. |
| 83 | + While the resources requested in the `<<config>>` MUST be created, the user-specified code (from `<<process>>`) MUST NOT be run at this time. |
| 84 | + Any updates to `<<config>>` after this step MUST NOT affect the container. |
| 85 | + |
| 86 | +. [[lifecycle-pre-start,step 3]] |
| 87 | + Once the container is created additional actions MAY be performed based on the features the runtime chooses to support. |
| 88 | + However, some actions might only be available based on the current state of the container (e.g. only available while it is started). |
| 89 | + |
| 90 | +. [[lifecycle-start,step 4]] |
| 91 | + Runtime's <<start>> command is invoked with the unique identifier of the container. |
| 92 | + The runtime MUST run the user-specified code, as specified by `<<process>>`. |
| 93 | + |
| 94 | +. [[lifecycle-exit,step 5]] |
| 95 | + The container's process is stopped. |
| 96 | + This MAY happen due to them erroring out, exiting, crashing or the runtime's <<kill>> operation being invoked. |
| 97 | + |
| 98 | + |
| 99 | +. [[lifecycle-delete,step 6]] |
| 100 | + Runtime's <<delete>> command is invoked with the unique identifier of the container. |
| 101 | + The container MUST be destroyed by undoing the steps performed during create phase (<<lifecycle-create>>). |
| 102 | + |
| 103 | +Errors |
| 104 | +~~~~~~ |
| 105 | + |
| 106 | +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. |
| 107 | +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. |
| 108 | + |
| 109 | +Operations |
| 110 | +~~~~~~~~~~ |
| 111 | + |
| 112 | +OCI compliant runtimes MUST support the following operations, unless the operation is not supported by the base operating system. |
| 113 | + |
| 114 | +[NOTE] |
| 115 | +These operations are not specifying any command line APIs, and the parameters are inputs for general operations. |
| 116 | + |
| 117 | +[[state-operation]] |
| 118 | +[caption="foo bar"] |
| 119 | +State |
| 120 | +^^^^^ |
| 121 | + |
| 122 | +`state <container-id>` |
| 123 | + |
| 124 | +This operation MUST generate an error if it is not provided the ID of a container. |
| 125 | +Attempting to query a container that does not exist MUST generate an error. |
| 126 | +This operation MUST return the state of a container as specified in <<state>>. |
| 127 | + |
| 128 | +[[create,create]] |
| 129 | +Create |
| 130 | +^^^^^^ |
| 131 | + |
| 132 | +`create <container-id> <path-to-bundle>` |
| 133 | + |
| 134 | +This operation MUST generate an error if it is not provided a path to the bundle and the container ID to associate with the container. |
| 135 | +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 and a new container MUST NOT be created. |
| 136 | +Using the data in `<<config,config.json>>`, this operation MUST create a new container. |
| 137 | +This means that all of the resources associated with the container MUST be created, however, the user-specified code MUST NOT be run at this time. |
| 138 | +If the runtime cannot create the container as specified in `<<config,config.json>>`, it MUST generate an error and a new container MUST NOT be created. |
| 139 | + |
| 140 | +Upon successful completion of this operation the <<status>> property of this container MUST be <<created>>. |
| 141 | + |
| 142 | +The runtime MAY validate `config.json` against this spec, either generically or with respect to the local system capabilities, before creating the container (<<lifecycle-create>>). |
| 143 | +Runtime callers who are interested in pre-create validation can run {implementation-testing}[bundle-validation tools] before invoking the create operation. |
| 144 | + |
| 145 | +Any changes made to the `<<config>>` after this operation will not have an effect on the container. |
| 146 | + |
| 147 | +[[start,start]] |
| 148 | +Start |
| 149 | +^^^^^ |
| 150 | + |
| 151 | +`start <container-id>` |
| 152 | + |
| 153 | +This operation MUST generate an error if it is not provided the container ID. |
| 154 | +Attempting to start a container that does not exist MUST generate an error. |
| 155 | +Attempting to start an already started container MUST have no effect on the container and MUST generate an error. |
| 156 | +This operation MUST run the user-specified code as specified by `<<process>>`. |
| 157 | + |
| 158 | +Upon successful completion of this operation the <<status>> property of this container MUST be <<running>>. |
| 159 | + |
| 160 | +[[kill,kill]] |
| 161 | +Kill |
| 162 | +^^^^ |
| 163 | + |
| 164 | +`kill <container-id> <signal>` |
| 165 | + |
| 166 | +This operation MUST generate an error if it is not provided the container ID. |
| 167 | +Attempting to send a signal to a container that is not running MUST have no effect on the container and MUST generate an error. |
| 168 | +This operation MUST send the specified signal to the process in the container. |
| 169 | + |
| 170 | +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>>. |
| 171 | + |
| 172 | +[[delete,delete]] |
| 173 | +Delete |
| 174 | +^^^^^^ |
| 175 | + |
| 176 | +`delete <container-id>` |
| 177 | + |
| 178 | +This operation MUST generate an error if it is not provided the container ID. |
| 179 | +Attempting to delete a container that does not exist MUST generate an error. |
| 180 | +Attempting to delete a container whose process is still running MUST generate an error. |
| 181 | +Deleting a container MUST delete the resources that were created during <<lifecycle-create>>. |
| 182 | +Note that resources associated with the container, but not created by this container, MUST NOT be deleted. |
| 183 | +Once a container is deleted its ID MAY be used by a subsequent container. |
| 184 | + |
| 185 | +[[runtime-hooks]] |
| 186 | +Hooks |
| 187 | +^^^^^ |
| 188 | + |
| 189 | +Many of the operations specified in this specification have "hooks" that allow for additional actions to be taken before or after each operation. |
| 190 | +See `<<hooks>>` for more information. |
0 commit comments