
# Images and layers

An OCI image (what Docker runs) is a stack of tar layers and a config. `untainer build` turns it
into a **micro-image**: a directory of static files that any web server or CDN can serve.

```
dist/node-24-alpine/
  manifest.json       how to run it: command, environment, user, ports, memory
  packages.json       what is installed in it, with licenses
  layers/<hash>.json  the chunks of each layer, in order
  chunks/             one file per chunk, compressed, named by its hash
  boot/<hash>.bin     the chunks its start reads, in a few large files (optional)
```

## One file system instead of a stack

The OCI layers are merged into **one read-only erofs file system**, built in a VM by
`mkfs.erofs` so that owners, modes, extended attributes and special files come out as Linux sees
them. A container gets a writable layer of its own on top (an overlay on a tmpfs), so it can
write anywhere and its writes go away with it.

A **base image** (`untainer base`) is the exception: an image built over a base keeps the base as
a layer of its own and adds only what it changes, so images that share a base share its chunks
in every cache.

## What the build records

- the **config**: command, entrypoint, environment, user, working directory, ports;
- with `--probe tcp:5432` (or `http:`, `exec:`), a **profile**: the image is started once and
  the build records how it gets ready, what its start reads, and how much memory it needs
  (`memoryMiB`, see [Memory](/concepts/memory));
- the **layout**: with a profile, the blocks its start reads are moved to the front of the
  layer, so that the start needs as few chunks as possible;
- the **boot bundle**: the chunks the start reads, in a few files fetched at once;
- **packages.json**: the packages and licenses its package managers recorded.

`--slim` removes what the start did not read (whole files by default, or chunks with
`--slim=chunks`); a container that later reads what was removed fails with `ERR_SLIM`, naming the
files. Measured: node:24-alpine 60.3 MB of chunks, 51.7 MB with `--slim`, 19.4 MB with
`--slim=chunks`; postgres:17-alpine 110.4, 31.1 and 14.5 MB ([`docs/findings.md`](https://github.com/OskarLebuda/untainer/blob/main/docs/findings.md), "Slim").

The format is in the [reference](/reference/format).
