While the various technologies we've looked at so far have been around for a while, Docker was the driving force that really made containers popular. About ten years, both they and a bunch of other organizations started the Open Container Initiative[1]Under the banner of the Linux Foundation. to standardize how containers and images will work.
They've produced three standards, two of which we will be looking at in this tutorial series:
- OCI Runtime Spec: for running containers
- OCI Image Format Spec: for managing images
The third is about distributing images (e.g. how to run a registry), which we won't be covering here:
The OCI Runtime Spec
The OCI Runtime Spec is about running containers, and at the heart of this technology is libcontainer, a library originally written by Docker for managing containers, but later donated to the OCI. runc was built on top of this, and is the official way of running OCI bundles.
An OCI bundle consists of two things:
- a config file (config.json)
- a root file system
Note that there's no requirement to use an overlay file system. You can, if you want, but it's not required.
The OCI Image Spec
An OCI image consists of several things:
- image manifest(s): file system layers and a config for a single operating system & architecture
- image index: a list of image manifests, for multiple operating systems & architectures
- configuration
The idea is that you are able to take an OCI Image and, for the CPU architecture and operating system you are on, generate an OCI Bundle from it, which runc can then use to launch a container.
This requires a lot more than just unpacking the file system and running the entrypoint command; you also have to consider e.g.
- environment variables
- what files and directories should be mounted into the container
- mapping UID's and GID's
- connecting stdin/stdout/stderr
An OCI Runtime Spec example
We'll start off by creating a config for a container:
$ runc spec $ ls -l total 4 -rw-r--r--. 1 taka taka 2500 Sep 27 02:19 config.json
If we take a look at this file, we can see various things of interest e.g.
$ jq . <config.json { "ociVersion": "1.0.2-dev", "process": { "terminal": true, "user": { "uid": 0, ← this will run as UID 0 i.e. root "gid": 0 }, "args": [ "sh" ← this is the entrypoint command ], "env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "TERM=xterm" ], ...snip... "root": { "path": "rootfs", ← where the root file system lives "readonly": true }, "mounts": [ { "destination": "/proc", "type": "proc", "source": "proc" }, { "destination": "/dev", "type": "tmpfs", "source": "tmpfs", "options": [ "nosuid", "strictatime", "mode=755", "size=65536k" ] }, ...snip... ], "linux": { ...snip... "namespaces": [ ↓ the Linux namespaces that will be created { "type": "pid" }, { "type": "network" }, { "type": "ipc" }, { "type": "uts" }, { "type": "mount" }, { "type": "cgroup" } ], ...snip... } }
Note that the UID/GID are both 0 i.e. things will be run inside the container as root. We want to avoid this, where possible, so let's create another config for a "rootless" container:
$ runc spec --rootless

If we diff the two config files, we can see that the main differences are:
- there are uid/gidMappings fields that map 0 (inside the container) to 1000 (outside)
- the network namespace is gone
- there is a new user namespace
The other part of an OCI bundle is a root file system, but rather than build our own, we'll grab a pre-made one. The config file defaults to the root file system being in a sub-directory called rootfs/:
"root": {
"path": "rootfs",
"readonly": true
},
so create that, and then download and unpack this file into it.
We now have the two things required for an OCI bundle, a config.json and a root file system, and so we can now launch a container from this bundle:
$ ls -l total 4 -rw-r--r--. 1 taka taka 2762 Sep 27 02:22 config.json drwxr-xr-x. 19 taka taka 380 Jul 15 10:42 rootfs $ runc run my-test / # ps PID USER TIME COMMAND 1 root 0:00 sh 7 root 0:00 ps
You should see the sh prompt - we're now running inside a container!
If you open another terminal, we can see it running:
$ runc list ID PID STATUS BUNDLE CREATED OWNER my-test 5578 running /home/taka/runc 2025-09-27T02:23:35.247812996Z taka
We can exit the container by pressing ^D, or killing it from another terminal:
$ runc kill my-test KILL
Note that runc kill sends a SIGTERM signal by default, which is not enough to terminate a shell, so we send it a KILL instead.
A note about managing terminal input/output
Managing terminal I/O seems to be, to put it mildly, a bit of a mess ![]()
Containers can be configured in config.json to handle terminal I/O in two ways:
- terminal: true → a new pseudo-terminal will be created (default)
- terminal: false → stdin is taken from the caller's stdin, stdout/stderr are sent to pre-existing handles.
Similarly, runc can run in two modes:
- foreground: the container runs in the foreground, until you end it
- detached: the container runs in the background, and the runc command returns immediately
This gives four different ways to run a container, and their closing advice is probably the way to go:
In general we recommend using foreground because it's the most straight-forward to use, with the only downside being that you will have a long-running runc process. Detached mode is difficult to get right and generally requires having your own stdio management.
While it would be nice to be able to run containers in the background, this raises of the question of how to manage its input/output. There are a few tutorials floating around on the intarwebs that talk about a tool called recvtty that can talk to a container over a UNIX socket, but while the source is in the repo, they don't seem to provide a compiled version:
The plan is to make the console socket API part of the spec, and that other people will implement more "enterprise" implementations -- recvtty is just used for our own integration tests (and also for messing around inside a shell).
I hope that I'm missing something here, since this is baffling to me. Containers can be run in the background, but they provide no way to talk to them, and they hope that someone else will step up and write something "more enterprise", whatever that's supposed to mean?!
Trying to run it from source gave errors complaining about mismatched Go versions and missing .mod files, and not being a Go guy, I eventually figured it wasn't worth the effort, and just ran my containers in the foreground ![]()
An OCI Image Spec example
If you haven't already got it, get Docker's hello-world image:
$ docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world 17eec7bbc9d7: Pull complete Digest: sha256:54e66cc1dd1fcb1c3c58bd8017914dbed8701e2d8c74d9262e26bd9cc1642d31 Status: Downloaded newer image for hello-world:latest docker.io/library/hello-world:latest
Export the image, and unpack it somewhere e.g.
$ docker save hello-world >/tmp/hello-world.tar $ mkdir /tmp/hello-world $ cd /tmp/hello-world $ tar xf ../hello-world.tar $ ls -l total 16 drwxr-xr-x. 3 taka taka 60 Aug 8 19:05 blobs -rw-r--r--. 1 taka taka 367 Jan 1 1970 index.json -rw-r--r--. 1 taka taka 460 Jan 1 1970 manifest.json -rw-r--r--. 1 taka taka 31 Jan 1 1970 oci-layout -rw-r--r--. 1 taka taka 94 Jan 1 1970 repositories
The starting point is manifest.json:
[
{
"Config": "blobs/sha256/1b44b5a3e06a9aae883e7bf25e45c100be0bb81a0e01b32de604f3ac44711634",
"RepoTags": [
"hello-world:latest"
],
"Layers": [
"blobs/sha256/53d204b3dc5ddbc129df4ce71996b8168711e211274c785de5e0d4eb68ec3851"
],
"LayerSources": {
"sha256:53d204b3dc5ddbc129df4ce71996b8168711e211274c785de5e0d4eb68ec3851": {
"mediaType": "application/vnd.oci.image.layer.v1.tar",
"size": 11776,
"digest": "sha256:53d204b3dc5ddbc129df4ce71996b8168711e211274c785de5e0d4eb68ec3851"
}
}
}
]
This tells us that the image's config is in 1b44b5a3e06a9aae883e7bf25e45c100be0bb81a0e01b32de604f3ac44711634, which contains things such as:
- environment variables
- the entrypoint command
- how to create the root filesystem
Note that while an image can handle multiple CPU architectures and operating systems, these settings are independent of that.
There is also a reference to a single layer in 53d204b3dc5ddbc129df4ce71996b8168711e211274c785de5e0d4eb68ec3851, so if we take a look inside that file:
$ cd blobs/sha256/ $ mkdir layer $ tar xf 53d204b3dc5ddbc129df4ce71996b8168711e211274c785de5e0d4eb68ec3851 -C layer $ ls -l layer/ total 12 -rwxr-xr-x. 1 taka taka 10072 Aug 13 22:17 hello
The layer contains a single file, the hello binary. We can even run it, from where it is:
$ layer/hello Hello from Docker! This message shows that your installation appears to be working correctly. ...snip... For more examples and ideas, visit: https://docs.docker.com/get-started/
So, this image contains a single file, a program that prints the "hello world" message. It's worth emphasizing that if this were a virtual machine image, we would need to include an entire operating system in the image, and the VM would boot up from that and run like a normal computer. But with containers, things run in the context of the host machine, partitioned off from the rest of the system with namespaces and control groups. There's no need to supply an OS, since the one that's already there will be used.










I am a 
