-
Notifications
You must be signed in to change notification settings - Fork 611
Expand file tree
/
Copy pathconfig.md
More file actions
698 lines (624 loc) · 22.3 KB
/
config.md
File metadata and controls
698 lines (624 loc) · 22.3 KB
Edit and raw actions
OlderNewer
1
# Container Configuration file
2
3
The container's top-level directory MUST contain a configuration file called `config.json`.
4
The canonical schema is defined in this document, but there is a JSON Schema in [`schema/config-schema.json`](schema/config-schema.json) and Go bindings in [`specs-go/config.go`](specs-go/config.go).
5
6
The configuration file contains metadata necessary to implement standard operations against the container.
7
This includes the process to run, environment variables to inject, sandboxing features to use, etc.
8
9
Below is a detailed description of each field defined in the configuration format.
10
11
## Specification version
12
13
* **`ociVersion`** (string, required) MUST be in [SemVer v2.0.0](http://semver.org/spec/v2.0.0.html) format and specifies the version of the Open Container Runtime Specification with which the bundle complies.
14
The Open Container Runtime Specification follows semantic versioning and retains forward and backward compatibility within major versions.
15
For example, if an implementation is compliant with version 1.0.1 of the spec, it is compatible with the complete 1.x series.
16
17
### Example
18
19
```json
20
"ociVersion": "0.1.0"
21
```
22
23
## Root Configuration
24
25
**`root`** (object, required) configures the container's root filesystem.
26
27
* **`path`** (string, required) Specifies the path to the root filesystem for the container.
28
A directory MUST exist at the path declared by the field.
29
* **`readonly`** (bool, optional) If true then the root filesystem MUST be read-only inside the container, defaults to false.
30
31
### Example
32
33
```json
34
"root": {
35
"path": "rootfs",
36
"readonly": true
37
}
38
```
39
40
## Mounts
41
42
**`mounts`** (array, optional) configures additional mounts (on top of [`root`](#root-configuration)).
43
The runtime MUST mount entries in the listed order.
44
The parameters are similar to the ones in [the Linux mount system call](http://man7.org/linux/man-pages/man2/mount.2.html).
45
46
* **`destination`** (string, required) Destination of mount point: path inside container.
47
For the Windows operating system, one mount destination MUST NOT be nested within another mount (e.g., c:\\foo and c:\\foo\\bar).
48
* **`type`** (string, required) The filesystem type of the filesystem to be mounted.
49
Linux: *filesystemtype* argument supported by the kernel are listed in */proc/filesystems* (e.g., "minix", "ext2", "ext3", "jfs", "xfs", "reiserfs", "msdos", "proc", "nfs", "iso9660").
50
Windows: ntfs.
51
* **`source`** (string, required) A device name, but can also be a directory name or a dummy.
52
Windows: the volume name that is the target of the mount point, \\?\Volume\{GUID}\ (on Windows source is called target).
53
* **`options`** (list of strings, optional) Mount options of the filesystem to be used.
54
Linux: [supported][mount.8-filesystem-independent] [options][mount.8-filesystem-specific] are listed in [mount(8)][mount.8].
55
56
### Example (Linux)
57
58
```json
59
"mounts": [
60
{
61
"destination": "/tmp",
62
"type": "tmpfs",
63
"source": "tmpfs",
64
"options": ["nosuid","strictatime","mode=755","size=65536k"]
65
},
66
{
67
"destination": "/data",
68
"type": "bind",
69
"source": "/volumes/testing",
70
"options": ["rbind","rw"]
71
}
72
]
73
```
74
75
### Example (Windows)
76
77
```json
78
"mounts": [
79
"myfancymountpoint": {
80
"destination": "C:\\Users\\crosbymichael\\My Fancy Mount Point\\",
81
"type": "ntfs",
82
"source": "\\\\?\\Volume\\{2eca078d-5cbc-43d3-aff8-7e8511f60d0e}\\",
83
"options": []
84
}
85
]
86
```
87
88
See links for details about [mountvol](http://ss64.com/nt/mountvol.html) and [SetVolumeMountPoint](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365561(v=vs.85).aspx) in Windows.
89
90
91
## Process configuration
92
93
**`process`** (object, required) configures the container process.
94
95
* **`terminal`** (bool, optional) specifies whether you want a terminal attached to that process, defaults to false.
96
* **`cwd`** (string, required) is the working directory that will be set for the executable.
97
This value MUST be an absolute path.
98
* **`env`** (array of strings, optional) contains a list of variables that will be set in the process's environment prior to execution.
99
Elements in the array are specified as Strings in the form "KEY=value".
100
The left hand side MUST consist solely of letters, digits, and underscores `_` as outlined in [IEEE Std 1003.1-2001](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html).
101
* **`args`** (array of strings, required) executable to launch and any flags as an array.
102
The executable is the first element and MUST be available at the given path inside of the rootfs.
103
If the executable path is not an absolute path then the search $PATH is interpreted to find the executable.
104
105
For Linux-based systems the process structure supports the following process specific fields:
106
107
* **`capabilities`** (array of strings, optional) capabilities is an array that specifies Linux capabilities that can be provided to the process inside the container.
108
Valid values are the strings for capabilities defined in [the man page](http://man7.org/linux/man-pages/man7/capabilities.7.html)
109
* **`rlimits`** (array of rlimits, optional) rlimits is an array of rlimits that allows setting resource limits for a process inside the container.
110
The kernel enforces the `soft` limit for a resource while the `hard` limit acts as a ceiling for that value that could be set by an unprivileged process.
111
Valid values for the 'type' field are the resources defined in [the man page](http://man7.org/linux/man-pages/man2/setrlimit.2.html).
112
* **`apparmorProfile`** (string, optional) apparmor profile specifies the name of the apparmor profile that will be used for the container.
113
For more information about Apparmor, see [Apparmor documentation](https://wiki.ubuntu.com/AppArmor)
114
* **`selinuxLabel`** (string, optional) SELinux process label specifies the label with which the processes in a container are run.
115
For more information about SELinux, see [Selinux documentation](http://selinuxproject.org/page/Main_Page)
116
* **`noNewPrivileges`** (bool, optional) setting `noNewPrivileges` to true prevents the processes in the container from gaining additional privileges.
117
[The kernel doc](https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt) has more information on how this is achieved using a prctl system call.
118
119
### User
120
121
The user for the process is a platform-specific structure that allows specific control over which user the process runs as.
122
123
#### Linux and Solaris User
124
125
For Linux and Solaris based systems the user structure has the following fields:
126
127
* **`uid`** (int, required) specifies the user ID in the [container namespace][container-namespace].
128
* **`gid`** (int, required) specifies the group ID in the [container namespace][container-namespace].
129
* **`additionalGids`** (array of ints, optional) specifies additional group IDs (in the [container namespace][container-namespace]) to be added to the process.
130
131
_Note: symbolic name for uid and gid, such as uname and gname respectively, are left to upper levels to derive (i.e. `/etc/passwd` parsing, NSS, etc)_
132
133
_Note: For Solaris, uid and gid specify the uid and gid of the process inside the container and need not be same as in the host._
134
135
### Example (Linux)
136
137
```json
138
"process": {
139
"terminal": true,
140
"user": {
141
"uid": 1,
142
"gid": 1,
143
"additionalGids": [5, 6]
144
},
145
"env": [
146
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
147
"TERM=xterm"
148
],
149
"cwd": "/root",
150
"args": [
151
"sh"
152
],
153
"apparmorProfile": "acme_secure_profile",
154
"selinuxLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675",
155
"noNewPrivileges": true,
156
"capabilities": [
157
"CAP_AUDIT_WRITE",
158
"CAP_KILL",
159
"CAP_NET_BIND_SERVICE"
160
],
161
"rlimits": [
162
{
163
"type": "RLIMIT_NOFILE",
164
"hard": 1024,
165
"soft": 1024
166
}
167
]
168
}
169
```
170
### Example (Solaris)
171
172
```json
173
"process": {
174
"terminal": true,
175
"user": {
176
"uid": 1,
177
"gid": 1,
178
"additionalGids": [2, 8]
179
},
180
"env": [
181
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
182
"TERM=xterm"
183
],
184
"cwd": "/root",
185
"args": [
186
"/usr/bin/bash"
187
],
188
}
189
```
190
191
192
## Hostname
193
194
* **`hostname`** (string, optional) configures the container's hostname as seen by processes running inside the container.
195
On Linux, you can only set this if your bundle creates a new [UTS namespace][uts-namespace].
196
197
### Example
198
199
```json
200
"hostname": "mrsdalloway"
201
```
202
203
## Platform
204
205
**`platform`** specifies the configuration's target platform.
206
207
* **`os`** (string, required) specifies the operating system family this image targets.
208
The runtime MUST generate an error if it does not support the configured **`os`**.
209
Bundles SHOULD use, and runtimes SHOULD understand, **`os`** entries listed in the Go Language document for [`$GOOS`][go-environment].
210
If an operating system is not included in the `$GOOS` documentation, it SHOULD be submitted to this specification for standardization.
211
* **`arch`** (string, required) specifies the instruction set for which the binaries in the image have been compiled.
212
The runtime MUST generate an error if it does not support the configured **`arch`**.
213
Values for **`arch`** SHOULD use, and runtimes SHOULD understand, **`arch`** entries listed in the Go Language document for [`$GOARCH`][go-environment].
214
If an architecture is not included in the `$GOARCH` documentation, it SHOULD be submitted to this specification for standardization.
215
216
### Example
217
218
```json
219
"platform": {
220
"os": "linux",
221
"arch": "amd64"
222
}
223
```
224
225
## Platform-specific configuration
226
227
[**`platform.os`**](#platform) is used to lookup further platform-specific configuration.
228
229
* **`linux`** (object, optional) [Linux-specific configuration](config-linux.md).
230
This SHOULD only be set if **`platform.os`** is `linux`.
231
* **`solaris`** (object, optional) [Solaris-specific configuration](config-solaris.md).
232
This SHOULD only be set if **`platform.os`** is `solaris`.
233
234
### Example (Linux)
235
236
```json
237
{
238
"platform": {
239
"os": "linux",
240
"arch": "amd64"
241
},
242
"linux": {
243
"namespaces": [
244
{
245
"type": "pid"
246
}
247
]
248
}
249
}
250
```
251
252
## Hooks
253
254
**`hooks`** (object, optional) configures callbacks for container lifecycle events.
255
Lifecycle hooks allow custom events for different points in a container's runtime.
256
Presently there are `Prestart`, `Poststart` and `Poststop`.
257
258
* [`Prestart`](#prestart) is a list of hooks to be run before the container process is executed
259
* [`Poststart`](#poststart) is a list of hooks to be run immediately after the container process is started
260
* [`Poststop`](#poststop) is a list of hooks to be run after the container process exits
261
262
Hooks allow one to run code before/after various lifecycle events of the container.
263
Hooks MUST be called in the listed order.
264
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.
265
266
Hook paths are absolute and are executed from the host's filesystem in the [runtime namespace][runtime-namespace].
267
268
### Prestart
269
270
The pre-start hooks are called after the container process is spawned, but before the user supplied command is executed.
271
They are called after the container namespaces are created on Linux, so they provide an opportunity to customize the container.
272
In Linux, for e.g., the network namespace could be configured in this hook.
273
274
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.
275
276
### Poststart
277
278
The post-start hooks are called after the user process is started.
279
For example this hook can notify user that real process is spawned.
280
281
If a hook returns a non-zero exit code, then an error is logged and the remaining hooks are executed.
282
283
### Poststop
284
285
The post-stop hooks are called after the container process is stopped.
286
Cleanup or debugging could be performed in such a hook.
287
If a hook returns a non-zero exit code, then an error is logged and the remaining hooks are executed.
288
289
### Example
290
291
```json
292
"hooks" : {
293
"prestart": [
294
{
295
"path": "/usr/bin/fix-mounts",
296
"args": ["fix-mounts", "arg1", "arg2"],
297
"env": [ "key1=value1"]
298
},
299
{
300
"path": "/usr/bin/setup-network"
301
}
302
],
303
"poststart": [
304
{
305
"path": "/usr/bin/notify-start",
306
"timeout": 5
307
}
308
],
309
"poststop": [
310
{
311
"path": "/usr/sbin/cleanup.sh",
312
"args": ["cleanup.sh", "-f"]
313
}
314
]
315
}
316
```
317
318
`path` is required for a hook.
319
`args` and `env` are optional.
320
`timeout` is the number of seconds before aborting the hook.
321
The semantics are the same as `Path`, `Args` and `Env` in [golang Cmd](https://golang.org/pkg/os/exec/#Cmd).
322
323
## Annotations
324
325
**`annotations`** (object, optional) contains arbitrary metadata for the container.
326
This information MAY be structured or unstructured.
327
Annotations are key-value maps.
328
329
```json
330
"annotations": {
331
"key1" : "value1",
332
"key2" : "value2"
333
}
334
```
335
336
## Configuration Schema Example
337
338
Here is a full example `config.json` for reference.
339
340
```json
341
{
342
"ociVersion": "0.5.0-dev",
343
"platform": {
344
"os": "linux",
345
"arch": "amd64"
346
},
347
"process": {
348
"terminal": true,
349
"user": {
350
"uid": 1,
351
"gid": 1,
352
"additionalGids": [
353
5,
354
6
355
]
356
},
357
"args": [
358
"sh"
359
],
360
"env": [
361
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
362
"TERM=xterm"
363
],
364
"cwd": "/",
365
"capabilities": [
366
"CAP_AUDIT_WRITE",
367
"CAP_KILL",
368
"CAP_NET_BIND_SERVICE"
369
],
370
"rlimits": [
371
{
372
"type": "RLIMIT_CORE",
373
"hard": 1024,
374
"soft": 1024
375
},
376
{
377
"type": "RLIMIT_NOFILE",
378
"hard": 1024,
379
"soft": 1024
380
}
381
],
382
"apparmorProfile": "acme_secure_profile",
383
"selinuxLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675",
384
"noNewPrivileges": true
385
},
386
"root": {
387
"path": "rootfs",
388
"readonly": true
389
},
390
"hostname": "slartibartfast",
391
"mounts": [
392
{
393
"destination": "/proc",
394
"type": "proc",
395
"source": "proc"
396
},
397
{
398
"destination": "/dev",
399
"type": "tmpfs",
400
"source": "tmpfs",
401
"options": [
402
"nosuid",
403
"strictatime",
404
"mode=755",
405
"size=65536k"
406
]
407
},
408
{
409
"destination": "/dev/pts",
410
"type": "devpts",
411
"source": "devpts",
412
"options": [
413
"nosuid",
414
"noexec",
415
"newinstance",
416
"ptmxmode=0666",
417
"mode=0620",
418
"gid=5"
419
]
420
},
421
{
422
"destination": "/dev/shm",
423
"type": "tmpfs",
424
"source": "shm",
425
"options": [
426
"nosuid",
427
"noexec",
428
"nodev",
429
"mode=1777",
430
"size=65536k"
431
]
432
},
433
{
434
"destination": "/dev/mqueue",
435
"type": "mqueue",
436
"source": "mqueue",
437
"options": [
438
"nosuid",
439
"noexec",
440
"nodev"
441
]
442
},
443
{
444
"destination": "/sys",
445
"type": "sysfs",
446
"source": "sysfs",
447
"options": [
448
"nosuid",
449
"noexec",
450
"nodev"
451
]
452
},
453
{
454
"destination": "/sys/fs/cgroup",
455
"type": "cgroup",
456
"source": "cgroup",
457
"options": [
458
"nosuid",
459
"noexec",
460
"nodev",
461
"relatime",
462
"ro"
463
]
464
}
465
],
466
"hooks": {
467
"prestart": [
468
{
469
"path": "/usr/bin/fix-mounts",
470
"args": [
471
"fix-mounts",
472
"arg1",
473
"arg2"
474
],
475
"env": [
476
"key1=value1"
477
]
478
},
479
{
480
"path": "/usr/bin/setup-network"
481
}
482
],
483
"poststart": [
484
{
485
"path": "/usr/bin/notify-start",
486
"timeout": 5
487
}
488
],
489
"poststop": [
490
{
491
"path": "/usr/sbin/cleanup.sh",
492
"args": [
493
"cleanup.sh",
494
"-f"
495
]
496
}
497
]
498
},
499
"linux": {
500
"devices": [
501
{
502
"path": "/dev/fuse",
503
"type": "c",
504
"major": 10,
505
"minor": 229,
506
"fileMode": 438,
507
"uid": 0,
508
"gid": 0
509
},
510
{
511
"path": "/dev/sda",
512
"type": "b",
513
"major": 8,
514
"minor": 0,
515
"fileMode": 432,
516
"uid": 0,
517
"gid": 0
518
}
519
],
520
"uidMappings": [
521
{
522
"hostID": 1000,
523
"containerID": 0,
524
"size": 32000
525
}
526
],
527
"gidMappings": [
528
{
529
"hostID": 1000,
530
"containerID": 0,
531
"size": 32000
532
}
533
],
534
"sysctl": {
535
"net.ipv4.ip_forward": "1",
536
"net.core.somaxconn": "256"
537
},
538
"cgroupsPath": "/myRuntime/myContainer",
539
"resources": {
540
"network": {
541
"classID": 1048577,
542
"priorities": [
543
{
544
"name": "eth0",
545
"priority": 500
546
},
547
{
548
"name": "eth1",
549
"priority": 1000
550
}
551
]
552
},
553
"pids": {
554
"limit": 32771
555
},
556
"hugepageLimits": [
557
{
558
"pageSize": "2MB",
559
"limit": 9223372036854772000
560
}
561
],
562
"oomScoreAdj": 100,
563
"memory": {
564
"limit": 536870912,
565
"reservation": 536870912,
566
"swap": 536870912,
567
"kernel": 0,
568
"kernelTCP": 0,
569
"swappiness": 0
570
},
571
"cpu": {
572
"shares": 1024,
573
"quota": 1000000,
574
"period": 500000,
575
"realtimeRuntime": 950000,
576
"realtimePeriod": 1000000,
577
"cpus": "2-3",
578
"mems": "0-7"
579
},
580
"disableOOMKiller": false,
581
"devices": [
582
{
583
"allow": false,
584
"access": "rwm"
585
},
586
{
587
"allow": true,
588
"type": "c",
589
"major": 10,
590
"minor": 229,
591
"access": "rw"
592
},
593
{
594
"allow": true,
595
"type": "b",
596
"major": 8,
597
"minor": 0,
598
"access": "r"
599
}
600
],
601
"blockIO": {
602
"blkioWeight": 10,
603
"blkioLeafWeight": 10,
604
"blkioWeightDevice": [
605
{
606
"major": 8,
607
"minor": 0,
608
"weight": 500,
609
"leafWeight": 300
610
},
611
{
612
"major": 8,
613
"minor": 16,
614
"weight": 500
615
}
616
],
617
"blkioThrottleReadBpsDevice": [
618
{
619
"major": 8,
620
"minor": 0,
621
"rate": 600
622
}
623
],
624
"blkioThrottleWriteIOPSDevice": [
625
{
626
"major": 8,
627
"minor": 16,
628
"rate": 300
629
}
630
]
631
}
632
},
633
"rootfsPropagation": "slave",
634
"seccomp": {
635
"defaultAction": "SCMP_ACT_ALLOW",
636
"architectures": [
637
"SCMP_ARCH_X86"
638
],
639
"syscalls": [
640
{
641
"name": "getcwd",
642
"action": "SCMP_ACT_ERRNO"
643
}
644
]
645
},
646
"namespaces": [
647
{
648
"type": "pid"
649
},
650
{
651
"type": "network"
652
},
653
{
654
"type": "ipc"
655
},
656
{
657
"type": "uts"
658
},
659
{
660
"type": "mount"
661
},
662
{
663
"type": "user"
664
},
665
{
666
"type": "cgroup"
667
}
668
],
669
"maskedPaths": [
670
"/proc/kcore",
671
"/proc/latency_stats",
672
"/proc/timer_stats",
673
"/proc/sched_debug"
674
],
675
"readonlyPaths": [
676
"/proc/asound",
677
"/proc/bus",
678
"/proc/fs",
679
"/proc/irq",
680
"/proc/sys",
681
"/proc/sysrq-trigger"
682
],
683
"mountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c715,c811"
684
},
685
"annotations": {
686
"key1": "value1",
687
"key2": "value2"
688
}
689
}
690
```
691
692
[container-namespace]: glossary.md#container-namespace
693
[go-environment]: https://golang.org/doc/install/source#environment
694
[runtime-namespace]: glossary.md#runtime-namespace
695
[uts-namespace]: http://man7.org/linux/man-pages/man7/namespaces.7.html
696
[mount.8-filesystem-independent]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-INDEPENDENT_MOUNT OPTIONS
697
[mount.8-filesystem-specific]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-SPECIFIC_MOUNT OPTIONS
698
[mount.8]: http://man7.org/linux/man-pages/man8/mount.8.html