The container's top-level directory MUST contain a configuration file called config.json
.
The canonical schema is defined in this document, but there is a JSON Schema in schema/config-schema.json
and Go bindings in specs-go/config.go
.
The configuration file contains metadata necessary to implement standard operations against the container. This includes the process to run, environment variables to inject, sandboxing features to use, etc.
Below is a detailed description of each field defined in the configuration format.
ociVersion
(string, required) MUST be in SemVer v2.0.0 format and specifies the version of the Open Container Runtime Specification with which the bundle complies. The Open Container Runtime Specification follows semantic versioning and retains forward and backward compatibility within major versions. For example, if an implementation is compliant with version 1.0.1 of the spec, it is compatible with the complete 1.x series.
"ociVersion": "0.1.0"
root
(object, required) configures the container's root filesystem.
path
(string, required) Specifies the path to the root filesystem for the container. A directory MUST exist at the path declared by the field.readonly
(bool, optional) If true then the root filesystem MUST be read-only inside the container, defaults to false.
"root": {
"path": "rootfs",
"readonly": true
}
mounts
(array, optional) configures additional mounts (on top of root
).
The runtime MUST mount entries in the listed order.
The parameters are similar to the ones in the Linux mount system call.
destination
(string, required) Destination of mount point: path inside container. For the Windows operating system, one mount destination MUST NOT be nested within another mount (e.g., c:\foo and c:\foo\bar).type
(string, required) The filesystem type of the filesystem to be mounted. Linux: filesystemtype argument supported by the kernel are listed in /proc/filesystems (e.g., "minix", "ext2", "ext3", "jfs", "xfs", "reiserfs", "msdos", "proc", "nfs", "iso9660"). Windows: ntfs.source
(string, required) A device name, but can also be a directory name or a dummy. Windows: the volume name that is the target of the mount point, \?\Volume{GUID}\ (on Windows source is called target).options
(list of strings, optional) Mount options of the filesystem to be used. Linux: [supported][mount.8-filesystem-independent] [options][mount.8-filesystem-specific] are listed in [mount(8)][mount.8].
"mounts": [
{
"destination": "/tmp",
"type": "tmpfs",
"source": "tmpfs",
"options": ["nosuid","strictatime","mode=755","size=65536k"]
},
{
"destination": "/data",
"type": "bind",
"source": "/volumes/testing",
"options": ["rbind","rw"]
}
]
"mounts": [
"myfancymountpoint": {
"destination": "C:\\Users\\crosbymichael\\My Fancy Mount Point\\",
"type": "ntfs",
"source": "\\\\?\\Volume\\{2eca078d-5cbc-43d3-aff8-7e8511f60d0e}\\",
"options": []
}
]
See links for details about mountvol and SetVolumeMountPoint in Windows.
process
(object, required) configures the container process.
terminal
(bool, optional) specifies whether you want a terminal attached to that process, defaults to false.cwd
(string, required) is the working directory that will be set for the executable. This value MUST be an absolute path.env
(array of strings, optional) with the same semantics as IEEE Std 1003.1-2001'senviron
.args
(array of strings, required) with similar semantics to IEEE Std 1003.1-2001execvp
's argv. This specification extends the IEEE standard in that at least one entry is REQUIRED, and that entry is used with the same semantics asexecvp
's file.
For Linux-based systems the process structure supports the following process specific fields:
capabilities
(array of strings, optional) capabilities is an array that specifies Linux capabilities that can be provided to the process inside the container. Valid values are the strings for capabilities defined in the man pagerlimits
(array of rlimits, optional) rlimits is an array of rlimits that allows setting resource limits for a process inside the container. The kernel enforces thesoft
limit for a resource while thehard
limit acts as a ceiling for that value that could be set by an unprivileged process. Valid values for the 'type' field are the resources defined in the man page.apparmorProfile
(string, optional) apparmor profile specifies the name of the apparmor profile that will be used for the container. For more information about Apparmor, see Apparmor documentationselinuxLabel
(string, optional) SELinux process label specifies the label with which the processes in a container are run. For more information about SELinux, see Selinux documentationnoNewPrivileges
(bool, optional) settingnoNewPrivileges
to true prevents the processes in the container from gaining additional privileges. The kernel doc has more information on how this is achieved using a prctl system call.
The user for the process is a platform-specific structure that allows specific control over which user the process runs as.
For Linux and Solaris based systems the user structure has the following fields:
uid
(int, required) specifies the user ID in the container namespace.gid
(int, required) specifies the group ID in the container namespace.additionalGids
(array of ints, optional) specifies additional group IDs (in the container namespace) to be added to the process.
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)
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.
"process": {
"terminal": true,
"user": {
"uid": 1,
"gid": 1,
"additionalGids": [5, 6]
},
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm"
],
"cwd": "/root",
"args": [
"sh"
],
"apparmorProfile": "acme_secure_profile",
"selinuxLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675",
"noNewPrivileges": true,
"capabilities": [
"CAP_AUDIT_WRITE",
"CAP_KILL",
"CAP_NET_BIND_SERVICE"
],
"rlimits": [
{
"type": "RLIMIT_NOFILE",
"hard": 1024,
"soft": 1024
}
]
}
"process": {
"terminal": true,
"user": {
"uid": 1,
"gid": 1,
"additionalGids": [2, 8]
},
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm"
],
"cwd": "/root",
"args": [
"/usr/bin/bash"
],
}
hostname
(string, optional) configures the container's hostname as seen by processes running inside the container. On Linux, you can only set this if your bundle creates a new UTS namespace.
"hostname": "mrsdalloway"
platform
specifies the configuration's target platform.
os
(string, required) specifies the operating system family this image targets. The runtime MUST generate an error if it does not support the configuredos
. Bundles SHOULD use, and runtimes SHOULD understand,os
entries listed in the Go Language document for$GOOS
. If an operating system is not included in the$GOOS
documentation, it SHOULD be submitted to this specification for standardization.arch
(string, required) specifies the instruction set for which the binaries in the image have been compiled. The runtime MUST generate an error if it does not support the configuredarch
. Values forarch
SHOULD use, and runtimes SHOULD understand,arch
entries listed in the Go Language document for$GOARCH
. If an architecture is not included in the$GOARCH
documentation, it SHOULD be submitted to this specification for standardization.
"platform": {
"os": "linux",
"arch": "amd64"
}
platform.os
is used to lookup further platform-specific configuration.
linux
(object, optional) Linux-specific configuration. This SHOULD only be set ifplatform.os
islinux
.solaris
(object, optional) Solaris-specific configuration. This SHOULD only be set ifplatform.os
issolaris
.
{
"platform": {
"os": "linux",
"arch": "amd64"
},
"linux": {
"namespaces": [
{
"type": "pid"
}
]
}
}
hooks
(object, optional) configures callbacks for container lifecycle events.
Lifecycle hooks allow custom events for different points in a container's runtime.
hooks
(object, optional) MAY contain any of the following properties:prestart
(array, optional) is an array of pre-start hooks. Entries in the array contain the following properties:path
(string, required) with similar semantics to IEEE Std 1003.1-2001execv
's path. This specification extends the IEEE standard in thatpath
MUST be absolute.args
(array of strings, required) with the same semantics as IEEE Std 1003.1-2001execv
's argv.env
(array of strings, optional) with the same semantics as IEEE Std 1003.1-2001'senviron
.timeout
(int, optional) is the number of seconds before aborting the hook.
poststart
(array, optional) is an array of post-start hooks. Entries in the array have the same schema as pre-start entries.poststop
(array, optional) is an array of post-stop hooks. Entries in the array have the same schema as pre-start entries.
Hooks allow one to run code before/after various lifecycle events of the container. Hooks MUST be called in the listed order. 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.
The pre-start hooks are called after the container process is spawned, but before the user supplied command is executed. They are called after the container namespaces are created on Linux, so they provide an opportunity to customize the container. In Linux, for e.g., the network namespace could be configured in this hook.
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.
The post-start hooks are called after the user process is started. For example this hook can notify user that real process is spawned.
If a hook returns a non-zero exit code, then an error is logged and the remaining hooks are executed.
The post-stop hooks are called after the container process is stopped. Cleanup or debugging could be performed in such a hook. If a hook returns a non-zero exit code, then an error is logged and the remaining hooks are executed.
"hooks" : {
"prestart": [
{
"path": "/usr/bin/fix-mounts",
"args": ["fix-mounts", "arg1", "arg2"],
"env": [ "key1=value1"]
},
{
"path": "/usr/bin/setup-network"
}
],
"poststart": [
{
"path": "/usr/bin/notify-start",
"timeout": 5
}
],
"poststop": [
{
"path": "/usr/sbin/cleanup.sh",
"args": ["cleanup.sh", "-f"]
}
]
}
annotations
(object, optional) contains arbitrary metadata for the container.
This information MAY be structured or unstructured.
Annotations are key-value maps.
"annotations": {
"key1" : "value1",
"key2" : "value2"
}
Here is a full example config.json
for reference.
{
"ociVersion": "0.5.0-dev",
"platform": {
"os": "linux",
"arch": "amd64"
},
"process": {
"terminal": true,
"user": {
"uid": 1,
"gid": 1,
"additionalGids": [
5,
6
]
},
"args": [
"sh"
],
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm"
],
"cwd": "/",
"capabilities": [
"CAP_AUDIT_WRITE",
"CAP_KILL",
"CAP_NET_BIND_SERVICE"
],
"rlimits": [
{
"type": "RLIMIT_CORE",
"hard": 1024,
"soft": 1024
},
{
"type": "RLIMIT_NOFILE",
"hard": 1024,
"soft": 1024
}
],
"apparmorProfile": "acme_secure_profile",
"selinuxLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675",
"noNewPrivileges": true
},
"root": {
"path": "rootfs",
"readonly": true
},
"hostname": "slartibartfast",
"mounts": [
{
"destination": "/proc",
"type": "proc",
"source": "proc"
},
{
"destination": "/dev",
"type": "tmpfs",
"source": "tmpfs",
"options": [
"nosuid",
"strictatime",
"mode=755",
"size=65536k"
]
},
{
"destination": "/dev/pts",
"type": "devpts",
"source": "devpts",
"options": [
"nosuid",
"noexec",
"newinstance",
"ptmxmode=0666",
"mode=0620",
"gid=5"
]
},
{
"destination": "/dev/shm",
"type": "tmpfs",
"source": "shm",
"options": [
"nosuid",
"noexec",
"nodev",
"mode=1777",
"size=65536k"
]
},
{
"destination": "/dev/mqueue",
"type": "mqueue",
"source": "mqueue",
"options": [
"nosuid",
"noexec",
"nodev"
]
},
{
"destination": "/sys",
"type": "sysfs",
"source": "sysfs",
"options": [
"nosuid",
"noexec",
"nodev"
]
},
{
"destination": "/sys/fs/cgroup",
"type": "cgroup",
"source": "cgroup",
"options": [
"nosuid",
"noexec",
"nodev",
"relatime",
"ro"
]
}
],
"hooks": {
"prestart": [
{
"path": "/usr/bin/fix-mounts",
"args": [
"fix-mounts",
"arg1",
"arg2"
],
"env": [
"key1=value1"
]
},
{
"path": "/usr/bin/setup-network"
}
],
"poststart": [
{
"path": "/usr/bin/notify-start",
"timeout": 5
}
],
"poststop": [
{
"path": "/usr/sbin/cleanup.sh",
"args": [
"cleanup.sh",
"-f"
]
}
]
},
"linux": {
"devices": [
{
"path": "/dev/fuse",
"type": "c",
"major": 10,
"minor": 229,
"fileMode": 438,
"uid": 0,
"gid": 0
},
{
"path": "/dev/sda",
"type": "b",
"major": 8,
"minor": 0,
"fileMode": 432,
"uid": 0,
"gid": 0
}
],
"uidMappings": [
{
"hostID": 1000,
"containerID": 0,
"size": 32000
}
],
"gidMappings": [
{
"hostID": 1000,
"containerID": 0,
"size": 32000
}
],
"sysctl": {
"net.ipv4.ip_forward": "1",
"net.core.somaxconn": "256"
},
"cgroupsPath": "/myRuntime/myContainer",
"resources": {
"network": {
"classID": 1048577,
"priorities": [
{
"name": "eth0",
"priority": 500
},
{
"name": "eth1",
"priority": 1000
}
]
},
"pids": {
"limit": 32771
},
"hugepageLimits": [
{
"pageSize": "2MB",
"limit": 9223372036854772000
}
],
"oomScoreAdj": 100,
"memory": {
"limit": 536870912,
"reservation": 536870912,
"swap": 536870912,
"kernel": 0,
"kernelTCP": 0,
"swappiness": 0
},
"cpu": {
"shares": 1024,
"quota": 1000000,
"period": 500000,
"realtimeRuntime": 950000,
"realtimePeriod": 1000000,
"cpus": "2-3",
"mems": "0-7"
},
"disableOOMKiller": false,
"devices": [
{
"allow": false,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 10,
"minor": 229,
"access": "rw"
},
{
"allow": true,
"type": "b",
"major": 8,
"minor": 0,
"access": "r"
}
],
"blockIO": {
"blkioWeight": 10,
"blkioLeafWeight": 10,
"blkioWeightDevice": [
{
"major": 8,
"minor": 0,
"weight": 500,
"leafWeight": 300
},
{
"major": 8,
"minor": 16,
"weight": 500
}
],
"blkioThrottleReadBpsDevice": [
{
"major": 8,
"minor": 0,
"rate": 600
}
],
"blkioThrottleWriteIOPSDevice": [
{
"major": 8,
"minor": 16,
"rate": 300
}
]
}
},
"rootfsPropagation": "slave",
"seccomp": {
"defaultAction": "SCMP_ACT_ALLOW",
"architectures": [
"SCMP_ARCH_X86"
],
"syscalls": [
{
"name": "getcwd",
"action": "SCMP_ACT_ERRNO"
}
]
},
"namespaces": [
{
"type": "pid"
},
{
"type": "network"
},
{
"type": "ipc"
},
{
"type": "uts"
},
{
"type": "mount"
},
{
"type": "user"
},
{
"type": "cgroup"
}
],
"maskedPaths": [
"/proc/kcore",
"/proc/latency_stats",
"/proc/timer_stats",
"/proc/sched_debug"
],
"readonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
],
"mountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c715,c811"
},
"annotations": {
"key1": "value1",
"key2": "value2"
}
}
[mount.8-filesystem-independent]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-INDEPENDENT_MOUNT OPTIONS [mount.8-filesystem-specific]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-SPECIFIC_MOUNT OPTIONS [mount.8]: http://man7.org/linux/man-pages/man8/mount.8.html