Skip to content

Commit da36556

Browse files
authored
Merge pull request containerd#10203 from deitch/content-flow-with-snapshot-updates
update documentation for content-flow
2 parents 78d3e20 + 1a5c711 commit da36556

File tree

1 file changed

+61
-13
lines changed

1 file changed

+61
-13
lines changed

docs/content-flow.md

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ Content exists in several areas in the containerd lifecycle:
1616
* containerd content store, under containerd's local storage space, for example, on a standard Linux installation at `/var/lib/containerd/io.containerd.content.v1.content`
1717
* snapshots, under containerd's local storage space, for example, on a standard Linux installation at `/var/lib/containerd/io.containerd.snapshotter.v1.<type>`. For an overlayfs snapshotter, that would be at `/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs`
1818

19+
A container needs a mountable, and often mutable, filesystem to run. This filesystem is created from the content in the content store.
1920
In order to create a container, the following must occur:
2021

21-
1. The image and all its content must be loaded into the content store. This normally happens via download from the OCI registry, but you can load content in directly as well.
22-
1. Committed snapshots must be created from each layer of content for the image.
23-
1. An active snapshot must be created on top of the final layer of content for the image.
22+
1. The image and all its content must be loaded into the local content store. This normally happens via download from the OCI registry, but you can load content in directly as well. This content is in the same format as in the registry.
23+
1. The layers from the image must be read and applied to a filesystem, creating what is known as a "committed snapshot". This is repeated for each layer in order. This process is known as "unpacking".
24+
1. A final mutable mountable filesystem, an "active snapshot", must be created on top of the final layer of content for the image.
2425

2526
A container now can be created, with its root filesystem as the active snapshot.
2627

@@ -351,11 +352,16 @@ they aren't there, they won't be removed.
351352

352353
### Snapshots
353354

354-
The content in the content store is immutable, but also in formats that often are unusable. For example,
355-
most container layers are in a tar-gzip format. One cannot simply mount a tar-gzip file. Even if one could,
356-
we want to leave our immutable content not only unchanged, but unchangeable, even by accident, i.e. immutable.
355+
The content in the content store is unusable directly by containers.
357356

358-
In order to use it, we create snapshots of the content.
357+
First, it is immutable, which makes it difficult for containers to use as a container filesystem.
358+
Second, the format itself often is unusable directly. For example,
359+
most container layers are in a tar-gzip format, with each tar-gzip file representing a single layer to be applied on top of the previous layers.
360+
One cannot simply mount a tar-gzip file. Even if one could, one would need to apply the changes from each layer on top of the previous.
361+
Third, some content layer media-types, like the standard container layer, include not only normal file additions and modifications,
362+
but removals. None of this can be used directly by a container, which requires a normal filesystem mount.
363+
364+
In order to use the content for an image, we create snapshots of the content.
359365

360366
The process is as follows:
361367

@@ -364,21 +370,43 @@ The process is as follows:
364370
1. The snapshotter commits the snapshot after the diff has been applied. This is now a "committed" snapshot.
365371
1. The committed snapshot is used as the parent for the next layer.
366372

373+
containerd ships with several built-in snapshotters, the default of which is `overlayfs`. You can choose a different snapshotter for each unpack
374+
of an image and creating a container. See [snapshotters](./snapshotters/README.md) and [PLUGINS](./PLUGINS.md).
375+
367376
Returning to our example, each layer will have a corresponding immutable snapshot layer. Recalling that
368377
our example has 6 layers, we expect to see 6 committed snapshots. The output has been sorted to make viewing
369378
easier; it matches the layers from the content store and manifest itself.
370379

371380
```console
372381
$ ctr snapshot ls
373382
KEY PARENT KIND
374-
sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c Committed
375-
sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6 sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c Committed
376-
sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396ca sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6 Committed
377-
sha256:aa4b58e6ece416031ce00869c5bf4b11da800a397e250de47ae398aea2782294 sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396ca Committed
378-
sha256:bc8b010e53c5f20023bd549d082c74ef8bfc237dc9bbccea2e0552e52bc5fcb1 sha256:aa4b58e6ece416031ce00869c5bf4b11da800a397e250de47ae398aea2782294 Committed
379383
sha256:33bd296ab7f37bdacff0cb4a5eb671bcb3a141887553ec4157b1e64d6641c1cd sha256:bc8b010e53c5f20023bd549d082c74ef8bfc237dc9bbccea2e0552e52bc5fcb1 Committed
384+
sha256:bc8b010e53c5f20023bd549d082c74ef8bfc237dc9bbccea2e0552e52bc5fcb1 sha256:aa4b58e6ece416031ce00869c5bf4b11da800a397e250de47ae398aea2782294 Committed
385+
sha256:aa4b58e6ece416031ce00869c5bf4b11da800a397e250de47ae398aea2782294 sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396ca Committed
386+
sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396ca sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6 Committed
387+
sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6 sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c Committed
388+
sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c Committed
389+
```
390+
391+
If we look in the snapshot directory, which is specific to each snapshotter, we see the snapshots themselves.
392+
393+
```bash
394+
# cd /var/lib/containerd
395+
# ls io.containerd.snapshotter.v1.overlayfs/snapshots/
396+
1 2 3 4 5 6
380397
```
381398

399+
There are 6 snapshots, each corresponding to one listed from `ctr snapshot ls`, above. The directories themselves contain the actual content:
400+
401+
```bash
402+
# ls io.containerd.snapshotter.v1.overlayfs/snapshots/1/fs
403+
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
404+
# ls io.containerd.snapshotter.v1.overlayfs/snapshots/2/fs
405+
etc var
406+
```
407+
408+
These are the unpacked and applied contents of the first and second layers.
409+
382410
#### Parents
383411

384412
Each snapshot has a parent, except for the root. It is a tree, or a stacked cake, starting with the first layer.
@@ -425,9 +453,29 @@ With the above in place, we know how to create an active snapshot that is useful
425453
need to [Prepare()](https://godoc.org/github.com/containerd/containerd/v2/snapshots#Snapshotter) the active snapshot,
426454
passing it an ID and the parent, in this case the top layer of committed snapshots.
427455

456+
We can see this by creating two containers from the same image. Both will create active snapshots on top of the top committed
457+
snapshot. However, we expect to see only 2 new snapshots, each active. The committed snapshots are unchanged, as they are reused.
458+
459+
```console
460+
# ctr container create docker.io/library/redis:5.0.6 redis1
461+
# ctr container create docker.io/library/redis:5.0.6 redis2
462+
ctr snapshot ls
463+
KEY PARENT KIND
464+
redis1 sha256:33bd296ab7f37bdacff0cb4a5eb671bcb3a141887553ec4157b1e64d6641c1cd Active
465+
redis2 sha256:33bd296ab7f37bdacff0cb4a5eb671bcb3a141887553ec4157b1e64d6641c1cd Active
466+
sha256:33bd296ab7f37bdacff0cb4a5eb671bcb3a141887553ec4157b1e64d6641c1cd sha256:bc8b010e53c5f20023bd549d082c74ef8bfc237dc9bbccea2e0552e52bc5fcb1 Committed
467+
sha256:bc8b010e53c5f20023bd549d082c74ef8bfc237dc9bbccea2e0552e52bc5fcb1 sha256:aa4b58e6ece416031ce00869c5bf4b11da800a397e250de47ae398aea2782294 Committed
468+
sha256:aa4b58e6ece416031ce00869c5bf4b11da800a397e250de47ae398aea2782294 sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396ca Committed
469+
sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396ca sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6 Committed
470+
sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6 sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c Committed
471+
sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c Committed```
472+
473+
The same 6 committed layers exist, but only 2 new active snapshots are created, one for each container. Both have the parent of the top committed snapshot,
474+
`sha256:33bd296ab7f37bdacff0cb4a5eb671bcb3a141887553ec4157b1e64d6641c1cd`.
475+
428476
Thus, the steps are:
429477

430478
1. Get the content into the content store, either via [Pull()](https://godoc.org/github.com/containerd/containerd/v2/client#Client.Pull), or via loading it in the [content.Store API](https://godoc.org/github.com/containerd/containerd/v2/content#Store)
431-
1. Unpack the image to create committed snapshots for each layer, using [image.Unpack()](https://godoc.org/github.com/containerd/containerd/v2/client#Image). Alternatively, if you use [Pull()](https://godoc.org/github.com/containerd/containerd/v2/client#Client.Pull), you can pass it an option to unpack when pulling, using [WithPullUnpack()](https://godoc.org/github.com/containerd/containerd/v2/client#WithPullUnpack)
479+
1. Unpack the image to create committed snapshots for each layer, using [image.Unpack()](https://godoc.org/github.com/containerd/containerd/v2/client#Image). Alternatively, if you use [Pull()](https://godoc.org/github.com/containerd/containerd/v2/client#Client.Pull), you can pass it an option to unpack when pulling, using [WithPullUnpack()](https://godoc.org/github.com/containerd/containerd/v2/client#WithPullUnpack).
432480
1. Create an active snapshot using [Prepare()](https://godoc.org/github.com/containerd/containerd/v2/snapshots#Snapshotter). You can skip this step if you plan on creating a container, as you can pass it as an option to the next step.
433481
1. Create a container using [NewContainer()](https://godoc.org/github.com/containerd/containerd/v2/client#Client.NewContainer), optionally telling it to create a snapshot with [WithNewSnapshot()](https://godoc.org/github.com/containerd/containerd/v2/client#WithNewSnapshot)

0 commit comments

Comments
 (0)